Reputation: 402
private System.Media.SoundPlayer sp;
public Form1()
{
InitializeComponent();
sp = new System.Media.SoundPlayer(Properties.Resources.main);
}
private void Form1_Load(object sender, EventArgs e)
{
sp.Play();
}
main is a MP3 from resources...I get the following errors: *The best overloaded method match for System.Media.SoundPlayer.SoundPlayer(System.IO.Stream)' has some invalid arguments
and
*cannot convert from 'byte[]' to 'System.IO.Stream'
Upvotes: 1
Views: 11981
Reputation: 10623
If you want to play some SOUNDS in your Dot Net(C#,Vb.net) Form. Then write this code in your project and it will play a SOUND during execution. Remember you should have a ".wave" file for this purposes.
using System.Media; // write this at the top of the Form
SoundPlayer my_sound = new SoundPlayer("F:/aeroplantakeover.wave"); //put your own .wave file path
my_sound.Play();
Upvotes: 1
Reputation: 2710
Microsoft do a great tutorial on this!
See: http://msdn.microsoft.com/en-us/library/windows/desktop/dd562692(v=vs.85).aspx
Good Luck.
Upvotes: 2
Reputation: 4199
Try this for wav.
System.Media.SoundPlayer player = new System.Media.SoundPlayer();
player.Stream = Properties.Resources.main;
player.Play();
Or this for MP3:
WMPLib.WindowsMediaPlayer wplayer = new WMPLib.WindowsMediaPlayer();
wplayer.URL = "main.mp3";
wplayer.Controls.Play();
Upvotes: 1