转:C#播放MP3的类
2011-11-22 08:12
267 查看
class MP3PLAYER { private const uint cchReturnLen = 256; private StringBuilder sRet = new StringBuilder((int)cchReturnLen); public static uint SND_ASYNC = 0x0001; // play asynchronously public static uint SND_FILENAME = 0x00020000; // name is file name [DllImport("winmm.dll")] public static extern uint mciSendString(string lpszCommand, StringBuilder lpszReturnString, uint cchReturn, IntPtr hwndCallback); [DllImport("Kernel32", CharSet = CharSet.Auto)] static extern Int32 GetShortPathName(String path, StringBuilder shortPath, Int32 shortPathLength); public void MyPlay(string name) { mciSendString(@"close all", null, 0, IntPtr.Zero); mciSendString(@"open " + name + " alias song", sRet, cchReturnLen, IntPtr.Zero); //打开,文件名的别名为song mciSendString("play song", sRet, cchReturnLen, IntPtr.Zero); //播放 } public string PlayStatus() { mciSendString("status song mode", sRet, cchReturnLen, IntPtr.Zero); //查看播放状态 return sRet.ToString(); } public void stop() //停止播放 { mciSendString(@"close all", null, 0, IntPtr.Zero); } public void Pause() { mciSendString("pause song", null, 0, IntPtr.Zero); } public void Close() { mciSendString("close song", null, 0, IntPtr.Zero); } }
测试支持128kbps的Mp3文件,192kbps以上播放不了。
相关文章推荐
- C#中用API实现MP3等音频文件的播放类
- C#中用API实现MP3等音频文件的播放类
- C#播放MP3的类
- C#调用mciSendString播放AVI和MP3的类
- C#播放MP3的类
- C# 调用系统winmm.dll 播放音乐wav mp3
- C#播放MP3的类
- c#制作自动播放的mp3
- 使用API函数播放MP3等音频文件的类设计(C#)
- C#播放本地MP3文件夹音乐
- C#使用MediaPlayer控件播放MP3等音乐文件
- 使用API函数播放MP3等音频文件的类设计(C#)
- C#播放MP3的类
- 【C#学习笔记】播放wma/mp3文件
- c# 播放mp3
- 播放MP3的类(C#)
- (转)C#中用API实现MP3等音频文件的播放类
- C#播放MP3音乐文件
- [导入]C#中用API实现MP3等音频文件的播放类
- c#播放mp3控件