private void MusicController_MediaPlaybackChanged(object sender, MediaPlaybackStateChangedEventArgs e) { switch (e.PlaybackState) { case PlaybackStateCode.Paused: btnPlayPause.SetCompoundDrawablesRelativeWithIntrinsicBounds(0, Resource.Drawable.ic_play_arrow_white_24dp, 0, 0); playbackState = PlaybackStateCode.Paused; MoveSeekbar(false); break; case PlaybackStateCode.Playing: btnPlayPause.SetCompoundDrawablesRelativeWithIntrinsicBounds(0, Resource.Drawable.ic_pause_white_24dp, 0, 0); playbackState = PlaybackStateCode.Playing; MoveSeekbar(true); break; case PlaybackStateCode.Stopped: btnPlayPause.SetCompoundDrawablesRelativeWithIntrinsicBounds(0, Resource.Drawable.ic_play_arrow_white_24dp, 0, 0); playbackState = PlaybackStateCode.Stopped; MoveSeekbar(false); break; default: break; } skbSeekSongTime.SetProgress((int)e.CurrentTime, true); }
public void OnClick(object sender, EventArgs e) { var v = (View)sender; PlaybackStateCode state = _playbackState == null ? PlaybackStateCode.None : _playbackState.State; switch (v.Id) { case Resource.Id.btnPlay: Logger.Debug("btnPlay pressed"); if (state == PlaybackStateCode.Paused || state == PlaybackStateCode.Stopped || state == PlaybackStateCode.None) { PlayMedia(); } else if (state == PlaybackStateCode.Playing) { PauseMedia(); } break; case Resource.Id.btnPrevious: Logger.Debug("btnPrevious"); SkipToPrevious(); break; case Resource.Id.btnNext: SkipToNext(); break; } }
private void MusicControllerKitkat_MediaPlaybackChanged(object sender, MediaPlaybackStateChangedKitkatEventArgs e) { switch (e.PlaybackState) { case RemoteControlPlayState.Paused: btnPlayPause.SetCompoundDrawablesRelativeWithIntrinsicBounds(0, Resource.Drawable.ic_play_arrow_white_24dp, 0, 0); playbackState = PlaybackStateCode.Paused; MoveSeekbar(false); break; case RemoteControlPlayState.Playing: btnPlayPause.SetCompoundDrawablesRelativeWithIntrinsicBounds(0, Resource.Drawable.ic_pause_white_24dp, 0, 0); playbackState = PlaybackStateCode.Playing; MoveSeekbar(true); break; case RemoteControlPlayState.Stopped: btnPlayPause.SetCompoundDrawablesRelativeWithIntrinsicBounds(0, Resource.Drawable.ic_play_arrow_white_24dp, 0, 0); playbackState = PlaybackStateCode.Stopped; MoveSeekbar(false); break; default: break; } }
private void UpdatePlaybackState(PlaybackStateCode state) { if (mediaSession == null || mediaPlayer == null) { return; } try { PlaybackState.Builder stateBuilder = new PlaybackState.Builder() .SetActions( PlaybackState.ActionPause | PlaybackState.ActionPlay | PlaybackState.ActionPlayPause | PlaybackState.ActionSkipToNext | PlaybackState.ActionSkipToPrevious | PlaybackState.ActionStop ) .SetState(state, Position, 1.0f, SystemClock.ElapsedRealtime()); mediaSession.SetPlaybackState(stateBuilder.Build()); OnStatusChanged(EventArgs.Empty); if (state == PlaybackStateCode.Playing || state == PlaybackStateCode.Paused) { StartNotification(); } } catch (Exception ex) { Console.WriteLine(ex); } }
public void OnClick(object sender, EventArgs e) { var v = (View)sender; PlaybackStateCode state = playbackState == null ? PlaybackStateCode.None : playbackState.State; switch (v.Id) { case Resource.Id.play_pause: LogHelper.Debug(Tag, "Play button pressed, in state " + state); if (state == PlaybackStateCode.Paused || state == PlaybackStateCode.Stopped || state == PlaybackStateCode.None) { PlayMedia(); } else if (state == PlaybackStateCode.Playing) { PauseMedia(); } break; case Resource.Id.skip_previous: LogHelper.Debug(Tag, "Start button pressed, in state " + state); SkipToPrevious(); break; case Resource.Id.skip_next: SkipToNext(); break; } }
public override void OnPlaybackStateChanged(PlaybackState state) { _playbackState = state; MusicStatus = state.State; OnMediaPlaybackChanged(new MediaPlaybackStateChangedEventArgs { PlaybackState = state.State, CurrentTime = state.Position }); base.OnPlaybackStateChanged(state); }
private void MusicController_MediaPlaybackChanged(object sender, MediaPlaybackStateChangedEventArgs e) { Activity?.RunOnUiThread(() => { switch (e.PlaybackState) { case PlaybackStateCode.Paused: SetMediaControlButtonsAvailability(true); btnPlayPause.SetCompoundDrawablesRelativeWithIntrinsicBounds(0, Resource.Drawable.ic_play_arrow_white_24dp, 0, 0); playbackState = PlaybackStateCode.Paused; //Start timeout to hide the MusicFragment (but only if the music method chosen is 'Pick a MediaSession' (0) //Otherwise, the Music Widget can only disappear when the notification is removed. (which is the correct behavior) if (configurationManager.RetrieveAValue(ConfigurationParameters.MusicWidgetMethod, "1") == "0") { StartTimeout(true); } MoveSeekbar(false); break; case PlaybackStateCode.Playing: SetMediaControlButtonsAvailability(true); btnPlayPause.SetCompoundDrawablesRelativeWithIntrinsicBounds(0, Resource.Drawable.ic_pause_white_24dp, 0, 0); playbackState = PlaybackStateCode.Playing; StartTimeout(false); MoveSeekbar(true); break; case PlaybackStateCode.Stopped: //HideMusicWidget(); btnPlayPause.SetCompoundDrawablesRelativeWithIntrinsicBounds(0, Resource.Drawable.ic_replay_white_24dp, 0, 0); playbackState = PlaybackStateCode.Stopped; MoveSeekbar(false); break; case PlaybackStateCode.Buffering: SetMediaControlButtonsAvailability(false); break; default: break; } skbSeekSongTime.SetProgress((int)e.CurrentTime / 1000, true); }); }
void UpdatePlaybackState(String error) { LogHelper.Debug(Tag, "updatePlaybackState, playback state=" + playback.State); var position = PlaybackState.PlaybackPositionUnknown; if (playback != null && playback.IsConnected) { position = playback.CurrentStreamPosition; } var stateBuilder = new PlaybackState.Builder() .SetActions(GetAvailableActions()); SetCustomAction(stateBuilder); PlaybackStateCode state = playback.State; // If there is an error message, send it to the playback state: if (error != null) { // Error states are really only supposed to be used for errors that cause playback to // stop unexpectedly and persist until the user takes action to fix it. stateBuilder.SetErrorMessage(error); state = PlaybackStateCode.Error; } stateBuilder.SetState(state, position, 1.0f, SystemClock.ElapsedRealtime()); // Set the activeQueueItemId if the current index is valid. if (QueueHelper.isIndexPlayable(currentIndexOnQueue, playingQueue)) { var item = playingQueue [currentIndexOnQueue]; stateBuilder.SetActiveQueueItemId(item.QueueId); } session.SetPlaybackState(stateBuilder.Build()); if (state == PlaybackStateCode.Playing || state == PlaybackStateCode.Paused) { mediaNotificationManager.StartNotification(); } }
public void OnPlaybackStatusChanged(PlaybackStateCode state) { UpdatePlaybackState(null); }
public void OnPlaybackStatusChanged (PlaybackStateCode state) { UpdatePlaybackState (null); }