WPF 播放音频:同步、异步、循环、播放与暂停

本地音频路径

public static string alarmFileName = 
System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase +Resources\AlarmVoice\ALARM7.WAV"
SoundPlayer player = new SoundPlayer(alarmFileName );
player.Play();
  • 同步播放:
System.Media.SoundPlayer player = new System.Media.SoundPlayer();
player.SoundLocation = alarmFileName;
player.Load();
player.PlaySync();
  • 异步播放:
System.Media.SoundPlayer player = new System.Media.SoundPlayer();
player.SoundLocation = alarmFileName ";
player.LoadAsync();
player.Play();
  • 循环播放:
System.Media.SoundPlayer player = new System.Media.SoundPlayer();
player.SoundLocation = alarmFileName ;
player.Load();
player.PlayLooping();

猜你喜欢

转载自blog.csdn.net/gao511147456/article/details/129225216
WPF