SoundPlayer 可以播放WAV文件。如果直接给出WAV文件的路径很简单。SoundPlayer player = new SoundPlayer();
player.SoundLocation = "C:\\Resources\\sound\\msg.wav";
player.Play();这样就可以了。
如果将WAV文件加入资源,如何用SoundPlayer播放该文件呢?很头疼。
player.SoundLocation = "C:\\Resources\\sound\\msg.wav";
player.Play();这样就可以了。
如果将WAV文件加入资源,如何用SoundPlayer播放该文件呢?很头疼。
编译的时候WAV是被编译到EXE中的
然后用这个方法即可解决
SoundPlayer player = new SoundPlayer(EIPNotify.Properties.Resources.msg);
player.Play();
//EIPNotify 工程名称。
最初我就是用你这种方法做的,但是后来发现问题,如果有人将WAV文件删除,整个程序就无法运行。将WAV加入资源就没有这个问题了。使用的音频文件作为资源嵌入到了程序中,这样在安装程序时就不再需要将外部的Wave文件一起打包了,同时这种方法也排除了在安装程序后音频文件被移除或替换的潜在可能。
using (Stream s = Properties.Resources.[NAME])
{
SoundPlayer sndPing = new SoundPlayer(s);
sndPing.Play();
}
或者调用Assembly.GetManifestResourceStream(resourceName))获得资源流
著個應當是你想要的
谢谢各位,gengchengxiang() 告诉了我想要的