可以用函数来播放,C#有专门播放音频的函数,写在窗体的加载事件中即可。
代码如下:
ResourceManager rm = ResourceManager.CreateFileBasedResourceManager("SoundResource", Application.StartupPath, null);//资源文件不带扩展名称
byte[] buffer = (byte[])rm.GetObject("Sound.wav");
FileStream fs = new FileStream("Sound.wav", FileMode.Create);//新建文件
BinaryWriter BWriter = new BinaryWriter(fs);//以二进制打开文件流
BWriter.Write(buffer, 0, buffer.Length);//从资源文件读取声音文件内容,写入到一个声音文件中
BWriter.Close();
fs.Close();
simpleSound = new SoundPlayer("Sound.wav");
simpleSound.Play();