C#WinForm中播放背景音乐(亲测可用)
using System.Runtime.InteropServices; public static uint SND_ASYNC = 0x0001; public static uint SND_FILENAME = 0x00020000; [DllImport("winmm.dll")] public static extern uint mciSendString(string lpstrCommand, string lpstrReturnString, uint uReturnLength, uint hWndCallback); //播放背景音乐 public void Play() { mciSendString(@"close temp_alias", null, 0, 0); mciSendString(@"open ""G:/Club_Card/此情可待.mp3"" alias temp_alias", null, 0, 0); mciSendString("play temp_alias repeat", null, 0, 0); } //关闭背景音乐 mciSendString(@"close temp_alias", null, 0, 0); mciSendString(@"close ""G:/Club_Card/此情可待.mp3"" alias temp_alias", null, 0, 0); mciSendString("pause temp_alias repeat", null, 0, 0);