在播放声音片段时,如何让声音只播放一次?

解决方案 »

  1.   

    wave的声音片段,我用的方法是:
    SoundPlayer player = new SoundPlayer("folder.wav");
                player.Play();
      

  2.   

    调用API方法来试试public class PlayWav
    {
        public PlayWav()
        {
            
        }    public enum PlaySoundFlags  : int
        {  
            SND_SYNC = 0x0000,
            SND_ASYNC = 0x0001,
            SND_NODEFAULT = 0x0002,
            SND_MEMORY = 0x0004,
            SND_LOOP = 0x0008,
            SND_NOSTOP = 0x0010,
            SND_NOWAIT = 0x00002000,
            SND_ALIAS = 0x00010000,
            SND_ALIAS_ID = 0x00110000, 
            SND_FILENAME = 0x00020000,
            SND_RESOURCE = 0x00040004
        }
            
        [DllImport("winmm")]
        public static extern bool PlaySound(string szSound, IntPtr hMod, PlaySoundFlags flags);    //改方法就是播放wav声音文件,参数是wav声音文件的全路径
        public static void Play(string strFileName)
        {
            PlaySound(strFileName, IntPtr.Zero, PlaySoundFlags.SND_FILENAME | PlaySoundFlags.SND_ASYNC);
        }
    }