How does one add a song onto a form?

Go to www.mentalis.org and check out their Multimedia and WaveFile classes. You can use them as they are or you can pick through the source code to see how they work and then write your own code.
 
If you would like it to play then use this:
VB.NET:
Expand Collapse Copy
Dim Player As Media.Soundplayer("song.wav")
Player.Play()
Player may use PlayLooping to play over and over. If you want it to start with a button put it in the button click event. To stop it use:
VB.NET:
Expand Collapse Copy
Player.Stop()
The sound file should be in a .WAV format
 
tahu191, System.Media Namespace namespace is new in the .NET Framework version 2.0, SaDaf asks in relation to .Net 1.1. SoundPlayer class is also limited to .Wav files should be noted.
 
tahu191 said:
I have used Media.Soundplayer in Vb 2003 using .Net Framework 1.1
I'd be interested to know exactly how you managed that.
 

Attachments

  • SoundPlayer.JPG
    SoundPlayer.JPG
    14.1 KB · Views: 108
In 1.1 you had to add a Media Player control to the form and it was a lil aggravating. It wasn't part of the framework as jmchinney pointed out. I think you may have gotten confused with the media player control that was also available in 1.0 which also played mp3.
 
If you would like it to play then use this:
Code:
Dim Player As Media.Soundplayer("song.wav")
Player.Play()
What am I doing wrong while using this code?

After pasting it just as it is I get song.wav underlined first saying that
"Array bounds cannot appear in type specifiers" and then Player underlined
saying "Name player is not declared".

Trying this:
VB.NET:
Expand Collapse Copy
         Dim Player As Media.SoundPlayer = "sound.wav"
         Player.Play()

I get just sound.wav underlined saying that "Value of type 'String' cannot
be converted to 'System.Media.SoundPlayer'".
 
Last edited:
Use the constructor (NEW keyword) to create a new instance of the SoundPlayer class:
VB.NET:
Expand Collapse Copy
Dim Player As [COLOR=darkgreen]NEW[/COLOR] Media.Soundplayer("song.wav")
 
Back
Top