using System.Runtime.InteropServices;
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 lpstrCommand,
string lpstrReturnString, uint uReturnLength, uint hWndCallback);
private void button1_Click(object sender, EventArgs e)
{
mciSendString(@"close temp_alias", null, 0, 0);
mciSendString(@"open ""E:/音乐/周杰伦-东风破.mp3"" alias temp_alias",
null, 0, 0);
mciSendString("play temp_alias", null, 0, 0);
}
本文介绍了一种使用C#语言通过Windows多媒体控制接口(MCI)播放MP3文件的方法。该方法首先关闭已存在的音频播放别名,然后打开指定路径下的MP3文件并设置别名,最后播放音频。代码中利用了DllImport属性调用winmm.dll中的mciSendString函数。
750

被折叠的 条评论
为什么被折叠?



