C#播放语音

Using System.Media.SoundPlayer;

OpenFileDialog o = new OpenFileDialog();
o.ShowDialog();
SoundPlayer player = new SoundPlayer(o.FileName);
player.Play();//这个方法只播放一遍
player.PlayLooping();//这个方法循环播放 

o.FileName此处可以直接指定音乐文件路径 




_________________________________________________________________
利用.NET自带的类库SoundPlayer来播放音乐,此类在System.Media命名空间中,支持同步和异步播放,也支持文件和流播放。
同步播放: 

System.Media.SoundPlayer player = new System.Media.SoundPlayer();
player.SoundLocation = @"d:\music\happy.mp3";
player.Load();
player.Play();

异步播放: 
System.Media.SoundPlayer player = new System.Media.SoundPlayer();
player.SoundLocation = @"d:\music\happy.mp3";
player.LoadAsync();
player.PlaySync();

循环播放: 

System.Media.SoundPlayer player = new System.Media.SoundPlayer();
player.SoundLocation = @"d:\music\happy.mp3";
player.Load();
player.PlayLooping(); 

你可能感兴趣的:(C#播放语音)