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#播放MP3的类
最新推荐文章于 2015-01-29 15:54:00 发布