MessageBox.Show("ok");
SoundPlayer s = new SoundPlayer(@"D:\MSG.wav");// 定义播放器,选择播放文件,在这里用的是系统声音
s.Load(); s.Play(); //播放音频 为什么播放不了文件,路径没问题
SoundPlayer s = new SoundPlayer(@"D:\MSG.wav");// 定义播放器,选择播放文件,在这里用的是系统声音
s.Load(); s.Play(); //播放音频 为什么播放不了文件,路径没问题
System.Media.SoundPlayer player = new System.Media.SoundPlayer();
player.SoundLocation = @""D:\MSG.wav";
player.Load();
player.Play();
// 定义PlaySound()要使用的常数
public const int SND_FILENAME = 0x00020000;
public const int SND_ASYNC = 0x0001; // 导入 Windows PlaySound() 函数
[DllImport("winmm.dll")]
public static extern bool PlaySound(string pszSound,
int hmod,
int fdwSound); public static void MsgSound(string str)
{
string wav = Application.StartupPath + "\\" + str;
PlaySound(wav,
0,
SND_FILENAME | SND_ASYNC);
}
SoundPlayer s = new SoundPlayer(@"D:\MSG.wav");
s.Play();
不加Load方法试试。