예제 #1
0
        /// <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
            }
        }
예제 #2
0
 public void PauseAudio()
 {
     if (PlayingAudio == null)
     {
         return;
     }
     PlayingAudio.IsPlaying = false;
     _playbackStoppedType   = StoppedType.StoppedByUser;
     Output?.Pause();
 }
예제 #3
0
 public void PlayAudio()
 {
     if (PlayingAudio == null)
     {
         return;
     }
     PlayingAudio.IsPlaying = true;
     _playbackStoppedType   = StoppedType.Ended;
     Output?.Play();
     _ = UpdateAudioAsync();
 }