您的位置:首页 > 编程语言 > C#

转: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# string null class path file