C# 使用System.Media.SoundPlayer播放wav格式的声音文件

using System.Media;
 
string szPath = Application.StartupPath + “\\SoundFile\\sound.wav”;
SoundPlayer soundplayer = new SoundPlayer();
声音文件路径:
soundplayer.SoundLocation = szPath;
播放方式:
①同步播放:
soundplayer.Load();
soundplayer.Play();
②异步播放:
soundplayer.LoadAsync();
soundplayer.PlaySync();
③循环播放:
soundplayer.Load();
soundplayer.PlayLooping();
④关闭://关闭时释放资源
soundplayer.Stop();
soundplayer.Dispose();

你可能感兴趣的:(C# 使用System.Media.SoundPlayer播放wav格式的声音文件)