Beispiel #1
0
 private void PlayOrPause_Click(object sender, RoutedEventArgs e)
 {
     if (IsPause)
     {
         PlayIcon.Kind = MaterialDesignThemes.Wpf.PackIconKind.Pause;
         if (SongPosition.Value == SongPosition.Maximum)
         {
             SongPosition.Value = 0;
         }
         if (Audio != null)
         {
             Audio.SetPosition(SongPosition.Value);
         }
         Wave.Play();
         Timer.Start();
     }
     else
     {
         PlayIcon.Kind = MaterialDesignThemes.Wpf.PackIconKind.Play;
         Wave.Pause();
         Timer.Stop();
     }
     IsPause = !IsPause;
 }
Beispiel #2
0
        public void SetPlaybackPosition(TimeSpan position)
        {
            _manuallySettingPlaybackPosition = true;

            if (position == TimeSpan.Zero)
            {
                StopAudio(_mediaItemId);
            }
            else
            {
                _audioFileReader?.SetPosition(position);
            }

            _manuallySettingPlaybackPosition = false;
        }
Beispiel #3
0
        public void PlayAudio(
            string mediaItemFilePath,
            Guid mediaItemId,
            TimeSpan startPosition,
            bool startFromPaused)
        {
            _mediaItemId       = mediaItemId;
            _mediaItemFilePath = mediaItemFilePath;

            if (!startFromPaused)
            {
                OnMediaChangeEvent(CreateMediaEventArgs(_mediaItemId, MediaChange.Starting));
            }

            Log.Debug($"PlayAudio - Media Id = {_mediaItemId}");

            if (_outputDevice == null)
            {
                _outputDevice = new WaveOutEvent();
                _outputDevice.PlaybackStopped += OnPlaybackStopped;
            }

            if (_audioFileReader == null)
            {
                _audioFileReader = new AudioFileReader(_mediaItemFilePath);
                _outputDevice.Init(_audioFileReader);
            }

            if (!startFromPaused && startPosition != TimeSpan.Zero)
            {
                _audioFileReader.SetPosition(startPosition);
            }

            _outputDevice.Play();
            _timer.Start();

            OnMediaChangeEvent(CreateMediaEventArgs(_mediaItemId, MediaChange.Started));
        }
Beispiel #4
0
 public void Seek(double _position)
 {
     audioFileReader?.SetPosition(_position);
 }