1.需要引用命名空间using System.Runtime.InteropServices;
这里只是做了个简单的播放功能,想了解更多查看它的官方文档
[DllImport("winmm.dll")] private static extern uint mciSendString(string lpstrCommand, string lpstrReturnString, uint uReturnLenth, uint hWndCallback); /// <summary> /// 播放指定的音乐 /// </summary> /// <param name="sound_Path"></param> public static void Play(string sound_Path) { mciSendString(@"colse temp_alias", null, 0, 0); mciSendString("open ""+sound_Path +"" alias temp_alias", null, 0, 0);//注意open后有一个空格,alias前面有一个空格 mciSendString("play temp_alias repeat", null, 0, 0); } /// <summary> /// 暂停播放 /// </summary> public static void Pause() { mciSendString(@"stop temp_alias", null, 0, 0); } /// <summary> /// 播放停止 /// </summary> public static void Stop() { mciSendString(@"close temp_alias",null,0,0); }