private void PlaybackSession_PlaybackStateChanged(MediaPlaybackSession sender, object args) { switch (sender.PlaybackState) { case MediaPlaybackState.Buffering: case MediaPlaybackState.Opening: //show pause IsPlaying = true; MediaTransportControls.PlaybackStatus = MediaPlaybackStatus.Changing; break; case MediaPlaybackState.Paused: case MediaPlaybackState.None: //show play IsPlaying = false; MediaTransportControls.PlaybackStatus = MediaPlaybackStatus.Paused; break; case MediaPlaybackState.Playing: //show pause IsPlaying = true; MediaTransportControls.PlaybackStatus = MediaPlaybackStatus.Playing; break; } IsPlayingChanged?.Invoke(this, new NepAppMediaPlayerManagerIsPlayingEventArgs(IsPlaying)); }
public void Pause() { mediaPlayer.Pause(); IsPlayingChanged?.Invoke(false); StopUpdateTimer(); ShowNotification(false); }
/// <summary> /// Initializes the wrapper. /// </summary> /// <param name="audioSourceDirectory">The directory of the audio source.</param> /// <returns>True if successful.</returns> public bool Initialize(string audioSourceDirectory) { try { _logger = AudioBandLogManager.GetLogger($"AudioSourceWrapper({new DirectoryInfo(audioSourceDirectory).Name})"); _logger.Debug("Initializing wrapper"); AppDomain.CurrentDomain.UnhandledException += (o, e) => _logger.Error(e.ExceptionObject as Exception, "Unhandled exception in wrapper"); _audioSource = AudioSourceLoader.LoadFromDirectory(audioSourceDirectory); _audioSource.Logger = new AudioSourceLogger(_audioSource.Name); _audioSource.SettingChanged += (o, e) => SettingChanged?.Invoke(this, e); _audioSource.TrackInfoChanged += (o, e) => TrackInfoChanged?.Invoke(this, e); _audioSource.IsPlayingChanged += (o, e) => IsPlayingChanged?.Invoke(this, e); _audioSource.TrackProgressChanged += (o, e) => TrackProgressChanged?.Invoke(this, e); _audioSource.VolumeChanged += (o, e) => VolumeChanged?.Invoke(this, e); _audioSource.ShuffleChanged += (o, e) => ShuffleChanged?.Invoke(this, e); _audioSource.RepeatModeChanged += (o, e) => RepeatModeChanged?.Invoke(this, e); _audioSourceSettingsList = _audioSource.GetSettings(); foreach (AudioSourceSetting setting in _audioSourceSettingsList) { _audioSourceSettings.Add(setting.Attribute.Name, setting); } _logger.Debug("Wrapper initialization complete"); return(true); } catch (Exception e) { _logger.Error(e); return(false); } }
/// <summary> /// 再生状態の変更を伝播します /// </summary> public void DoIsPlayingChanged() { if (IsPlayingChanged != null) { IsPlayingChanged.Invoke(this, new EventArgs()); } }
public void Play() { mediaPlayer.Start(); IsPlayingChanged?.Invoke(true); StartUpdateTimer(); ShowNotification(true); }
public void Stop() { avAudioPlayer.Stop(); IsPlayingChanged?.Invoke(false); StopUpdateTimer(); MPNowPlayingInfoCenter.DefaultCenter.NowPlaying = null; }
public void Pause() { avAudioPlayer.Pause(); IsPlayingChanged?.Invoke(false); StopUpdateTimer(); UpdateNowPlayingInfo(0); }
public void Play() { avAudioPlayer.Play(); IsPlayingChanged?.Invoke(true); StartUpdateTimer(); UpdateNowPlayingInfo(avAudioPlayer.Rate); }
private void NotifyPlayerState() { var playing = _itunesControls.IsPlaying; if (_isPlaying == playing) { return; } _isPlaying = playing; IsPlayingChanged?.Invoke(this, _isPlaying); }
private void NotifyState() { var isPlaying = _ipc.GetPlayState().HasFlag(MusicBeeIPC.PlayState.Playing); if (isPlaying == _isPlaying) { return; } _isPlaying = isPlaying; IsPlayingChanged?.Invoke(this, _isPlaying); }
public void Stop() { mediaPlayer.Stop(); StopUpdateTimer(); IsPlayingChanged?.Invoke(false); DismissNotification(); ProgressChanged?.Invoke(0); mediaPlayer.Reset(); var path = CopyAudioToTemp(currentAudio); mediaPlayer.SetDataSource(path); mediaPlayer.Prepare(); }
public async Task PlayAsync(Episode episode, Show show, bool isPlaying, double position = 0) { if (episode == null) { return; } var isOtherEpisode = CurrentEpisode?.Id != episode.Id; CurrentShow = show; if (isOtherEpisode) { CurrentEpisode = episode; if (audioService.IsPlaying) { await InternalPauseAsync(); } await audioService.InitializeAsync(CurrentEpisode.Url.ToString()); if (isPlaying) { await InternalPlayAsync(initializePlayer : false, position); } else { await InternalPauseAsync(); } NewEpisodeAdded?.Invoke(this, EventArgs.Empty); } else { if (isPlaying) { await InternalPlayAsync(initializePlayer : false, position); } else { await InternalPauseAsync(); } } IsPlayingChanged?.Invoke(this, EventArgs.Empty); }
private void ShutdownPreviousPlaybackSession() { if (CurrentStreamer == null && CurrentPlayer == null) { return; } if (CurrentStreamer != null) { CurrentStreamer.MetadataChanged -= Streamer_MetadataChanged; if (IsPlaying) { CurrentStreamer.Pause(); } CurrentStreamer.Dispose(); CurrentStreamer = null; } if (CurrentPlayer != null) { CurrentPlayer.MediaFailed -= CurrentPlayer_MediaFailed; CurrentPlayerSession.PlaybackStateChanged -= PlaybackSession_PlaybackStateChanged; CurrentPlayer.Dispose(); CurrentPlayer = null; } CurrentStream = null; NepApp.SongManager.ResetMetadata(); SetMediaEngagement(false); IsPlaying = false; if (MediaTransportControls != null) { MediaTransportControls.PlaybackStatus = MediaPlaybackStatus.Closed; } IsPlayingChanged?.Invoke(this, new NepAppMediaPlayerManagerIsPlayingEventArgs(IsPlaying)); }
/// <summary> /// Called when the AVAudioPlayer finishes playing. Stops the update timer, informs listeners and updates the isPlaying state. /// </summary> /// <param name="sender">The sender of the event.</param> /// <param name="args">The event parameters</param> private void OnAvAudioPlayerOnFinishedPlaying(object sender, AVStatusEventArgs args) { StopUpdateTimer(); AudioCompleted?.Invoke(); IsPlayingChanged?.Invoke(IsPlaying); }
private void OnIsPlayingChanged(object sender, IsPlayingChangedEventArgs e) { IsPlayingChanged?.Invoke(this, new SubscriptionsEventArgs <ILibrary, IsPlayingChangedEventArgs>(sender, e)); }
/// <summary> /// Fire an IsPlayingChanged event /// </summary> public void OnIsPlayingChangedChanged() { IsPlayingChanged?.Invoke(this, new RoutedEventArgs()); }
/// <summary> /// Called when the media player finishes playing. Stops the update timer, informs listeners and updates the isPlaying state. /// </summary> /// <param name="sender">The sender of the event.</param> /// <param name="eventArgs">The event parameters</param> private void MediaPlayerOnCompletion(object sender, EventArgs eventArgs) { StopUpdateTimer(); AudioCompleted?.Invoke(); IsPlayingChanged?.Invoke(IsPlaying); }