本文主要是介绍.Net下C#播放WAV,WAVE文件,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
.Net下C#播放WAV,WAVE文件 /*------------------------------------------------------------ * CopyRight: * * FileName: WavFilePlayer.cs * Author: 武眉博(活靶子) huobazi@aspxboy.com * *-----------------------------------------------------------*/ /// From:http://www.codeguru.com/Csharp/Csharp/cs_graphics/sound/article.php/c6143/ /// 也可参考:http://www.eggheadcafe.com/articles/20030302.asp
using System; using System.Runtime.InteropServices;
namespace CTI { /// <summary> /// WavFilePlayer 的摘要说明。 /// 播放Wav格式的文件 /// Author: 武眉博 huobazi@aspxboy.com /// </summary> public class WavFilePlayer {
[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 Play(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); } } }
这篇关于.Net下C#播放WAV,WAVE文件的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!