/// <summary> /// If audio is still playing, make sure to stop the audio first before trying to play a new one. /// </summary> /// <param name="audio"></param> public void ChangeAudio(AudioViewModel audio) { if (audio == PlayingAudio) { return; } if (AudioFileReader != null) { _playbackStoppedType = StoppedType.StoppedByUser; StopAudio(); } try { AudioFileReader = new AudioFileReader(audio.Song.Path) { Volume = Volume }; var wc = new WaveChannel32(AudioFileReader) { PadWithZeroes = false }; Output.Init(wc); PlayingAudio = audio; Output.PlaybackStopped += (sender, args) => { PlayingAudio.IsPlaying = false; }; } catch (Exception) { //ignored } }
public void PauseAudio() { if (PlayingAudio == null) { return; } PlayingAudio.IsPlaying = false; _playbackStoppedType = StoppedType.StoppedByUser; Output?.Pause(); }
public void PlayAudio() { if (PlayingAudio == null) { return; } PlayingAudio.IsPlaying = true; _playbackStoppedType = StoppedType.Ended; Output?.Play(); _ = UpdateAudioAsync(); }