using System.Runtime.InteropServices; 在调用API时先引用
[DllImport("winmm")]
public static extern bool PlaySound(string szSound, IntPtr hMod, int i); //声明API:PlaySound
调用:
PlaySound(@"声音文件路径",IntPtr.Zero,1);
第二种方法:
利用windows media player播放声音
System.Media.SoundPlayer media = new System.Media.SoundPlayer(@"声音文件路径");
mdeia.Play();
DllImport("winmm.dll", SetLastError=true, CallingConvention=CallingConvention.Winapi)]
public static extern int waveOutSetVolume(int uDeviceID, int dwVolume);