播放wav文件

来源:互联网 发布:js foreach遍历对象 编辑:程序博客网 时间:2024/05/01 20:12
using System;
using System.Runtime.InteropServices;
public class WAVSounds
{
    [DllImport(
"WinMM.dll")]
   
public static extern bool  PlaySound(byte[]wfname, int fuSound);

   
public int SND_SYNC       = 0x0000;
   
public int SND_ASYNC      = 0x0001;
   
public int SND_NODEFAULT  = 0x0002;
   
public int SND_MEMORY     = 0x0004;
   
public int SND_LOOP       = 0x0008;
   
public int SND_NOSTOP     = 0x0010;
   
public int SND_NOWAIT      = 0x00002000;
   
public int SND_ALIAS       = 0x00010000;
   
public int SND_ALIAS_ID    = 0x00110000;
   
public int SND_FILENAME    = 0x00020000;
   
public int SND_RESOURCE    = 0x00040004;
   
public int SND_PURGE       = 0x0040;
   
public int SND_APPLICATION = 0x0080;

   
public void PlayFile(string wfname,int SoundFlags)
    {
       
byte[] bname = new Byte[256];
        bname = System.Text.Encoding.ASCII.GetBytes(wfname);
        PlaySound(bname,SoundFlags);
    }

   
public void StopPlay()
    {
        PlaySound(
null,SND_PURGE);
    }
}
原创粉丝点击