[DllImport("winmm.dll")] public static extern long PlaySound(String fileName, long a, long b); [DllImport("winmm.dll")] public static extern long mciSendString(string lpstrCommand, string lpstrReturnString, long length, long hwndcallback); /// <summary> /// 播放音乐文件(重复) /// </summary> /// <param name="p_FileName">音乐文件名称</param> public static void PlayMusic_Repeat(string p_FileName) { try { mciSendString(@"close temp_music", " ", 0, 0); mciSendString(@"open " + p_FileName + " alias temp_music", " ", 0, 0); mciSendString(@"play temp_music repeat", " ", 0, 0); } catch { } } /// <summary> /// 播放音乐文件 /// </summary> /// <param name="p_FileName">音乐文件名称</param> public static void PlayMusic(string p_FileName) { try { mciSendString(@"close temp_music", " ", 0, 0); mciSendString(@"open " + p_FileName + " alias temp_music", " ", 0, 0); mciSendString(@"play temp_music", " ", 0, 0); } catch { } } /// <summary> /// 停止当前音乐播放 /// </summary> /// <param name="p_FileName">音乐文件名称</param> public static void StopMusic(string p_FileName) { try { mciSendString(@"close " + p_FileName, " ", 0, 0); } catch { } } private void button18_Click(object sender, EventArgs e) { //getMessageMethod(); PlayMusic_Repeat("你有新的消息"); }