C#2005中播放声音的方法与C#2003不同,C#2005中给提供的一个专门用播放声音的类SoundPlayer,在System.Media命名空间中。而C#2003是通过调用WinAPI做的。 private void playSoundFromResource() 查MSDN发现前一个参数是SerializationInfo 类型的,可是上面给的那个GetType()返回的是Type,所以总报错,不知是不是我用错了。 后来我用了第二个SoundPlayer (Stream) 可以运行通过,并且可以正常播放声音,以下是我的实现代码: SoundPlayer sp = new SoundPlayer(Properties.Resources.notify); Properties.Resources.notify 是我调用的嵌入的声音资源。我的声音文件是notify.wav. |