1个回答
展开全部
2种方法:
[DllImport("winmm.dll")]
private static extern bool PlaySound(string pszSound, int hmod, int fdwSound);
public const int SND_FILENAME = 0x00020000;
public const int SND_ASYNC = 0x0001;
public const int SND_LOOP = 8;
/// <summary>
/// 调用API播放声音
/// </summary>
/// <param name="name">声音文件名</param>
public static void PlayMusic(string name)
{
try
{
PlaySound(name, 0, SND_ASYNC | SND_FILENAME | SND_LOOP);
}
catch (Exception err)
{
MessageBox.Show(err.Message);
}
}
方法2:
[DllImport("winmm.dll")]
public extern static int mciSendString(string command,IntPtr responseBuffer, int bufferLength, int nothing);
WinAPI.mciSendString("open D:\\GM01.mid alias song ", new IntPtr(0), 0, 0);
WinAPI.mciSendString("play song", new IntPtr(0), 0, 0);
[DllImport("winmm.dll")]
private static extern bool PlaySound(string pszSound, int hmod, int fdwSound);
public const int SND_FILENAME = 0x00020000;
public const int SND_ASYNC = 0x0001;
public const int SND_LOOP = 8;
/// <summary>
/// 调用API播放声音
/// </summary>
/// <param name="name">声音文件名</param>
public static void PlayMusic(string name)
{
try
{
PlaySound(name, 0, SND_ASYNC | SND_FILENAME | SND_LOOP);
}
catch (Exception err)
{
MessageBox.Show(err.Message);
}
}
方法2:
[DllImport("winmm.dll")]
public extern static int mciSendString(string command,IntPtr responseBuffer, int bufferLength, int nothing);
WinAPI.mciSendString("open D:\\GM01.mid alias song ", new IntPtr(0), 0, 0);
WinAPI.mciSendString("play song", new IntPtr(0), 0, 0);
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询