if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mSession.setPlaybackState(new PlaybackState.Builder() .setState(playState, position(), 1.0f) .setActions(PlaybackState.ACTION_PLAY | PlaybackState.ACTION_PAUSE | PlaybackState.ACTION_PLAY_PAUSE | PlaybackState.ACTION_SKIP_TO_NEXT | PlaybackState.ACTION_SKIP_TO_PREVIOUS) .setState(playState, position(), 1.0f) .setActions(PlaybackState.ACTION_PLAY | PlaybackState.ACTION_PAUSE | PlaybackState.ACTION_PLAY_PAUSE | PlaybackState.ACTION_SKIP_TO_NEXT | PlaybackState.ACTION_SKIP_TO_PREVIOUS)
@Override public void closePlayer() { stopVideo(); PlaybackState.Builder stateBuilder = new PlaybackState.Builder(); stateBuilder.setState(PlaybackState.STATE_PAUSED, 12, 1); mMediaSession.setPlaybackState(stateBuilder.build()); mMediaSession.setActive(false); Log.i(TAG, "closePlayer : " + mMediaSession.isActive()); }
/** * Update the current media player state, optionally showing an error message. * * @param error if not null, error message to present to the user. */ private void updatePlaybackState(String error) { long position = PlaybackState.PLAYBACK_POSITION_UNKNOWN; int state = PlaybackState.STATE_PAUSED; if(PlaybackService.hasInstance()) { if (PlaybackService.get(this).isPlaying()) { state = PlaybackState.STATE_PLAYING; } position = PlaybackService.get(this).getPosition(); } PlaybackState.Builder stateBuilder = new PlaybackState.Builder() .setActions(getAvailableActions()); setCustomAction(stateBuilder); // 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 = PlaybackState.STATE_ERROR; } stateBuilder.setState(state, position, 1.0f, SystemClock.elapsedRealtime()); mSession.setPlaybackState(stateBuilder.build()); } // 'DriveSafe' icons need to meet contrast requirement, and as such are usually
.setState(playbackState, service.getPosition(), 1.0f) .setActions(PlaybackState.ACTION_PLAY | PlaybackState.ACTION_STOP | PlaybackState.ACTION_PAUSE | PlaybackState.ACTION_PLAY_PAUSE | PlaybackState.ACTION_SKIP_TO_NEXT | PlaybackState.ACTION_SKIP_TO_PREVIOUS)
public static void updateMediaSession(boolean updateMetadata, MediaMetadata.Builder mediaBuilder, final MediaSession mediaSession, final int playbackState, final long position, final float speed) { if (mediaSession.isActive()) { if (updateMetadata) { mediaSession.setMetadata(mediaBuilder.build()); } PlaybackState.Builder stateBuilder = new PlaybackState.Builder(); stateBuilder.setState(playbackState, position, speed); mediaSession.setPlaybackState(stateBuilder.build()); } } }
private void updatePlaybackState(int position) { PlaybackState.Builder stateBuilder = new PlaybackState.Builder() .setActions(getAvailableActions()); int state = PlaybackState.STATE_PLAYING; if (mPlaybackState == LeanbackPlaybackState.PAUSED) { state = PlaybackState.STATE_PAUSED; } stateBuilder.setState(state, position, 1.0f); mSession.setPlaybackState(stateBuilder.build()); }
public static Object newInstance(int state, long position, long bufferedPosition, float speed, long actions, CharSequence errorMessage, long updateTime) { PlaybackState.Builder stateObj = new PlaybackState.Builder(); stateObj.setState(state, position, speed, updateTime); stateObj.setBufferedPosition(bufferedPosition); stateObj.setActions(actions); stateObj.setErrorMessage(errorMessage); return stateObj.build(); } }