先看下播放mp3
[System.Runtime.InteropServices.DllImport("winmm.dll", EntryPoint = "mciSendStringA", ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Ansi, SetLastError = true)]
private static extern int mciSendStringA(string lpstrCommand, string lpstrReturnString, int uReturnLength, int hwndCallback);
PlayMidiFile(Application.StartupPath + "//sound//注意哈.mp3");
需要注意的是,这个播放功能在新线程上可能不起作用,像Task.Run或backgroundworker控件
await Task.Run(() =>
{
PlayMidiFile(Application.StartupPath + "//sound//注意哈.mp3");
});
如果只播放系统声音
[DllImport("kernel32.dll")]
public static extern bool Beep(int freq, int duration);//播放系统声音用
Beep(800,300);
1700




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



