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();
posted @ 2019-12-13 10:53  ₯㎕~  阅读(473)  评论(0编辑  收藏  举报