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) .build()); .setActions(PlaybackState.ACTION_PLAY | PlaybackState.ACTION_PAUSE | PlaybackState.ACTION_PLAY_PAUSE | PlaybackState.ACTION_SKIP_TO_NEXT | PlaybackState.ACTION_SKIP_TO_PREVIOUS) .build());
/** * 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
.setActions(PlaybackState.ACTION_PLAY | PlaybackState.ACTION_STOP | PlaybackState.ACTION_PAUSE | PlaybackState.ACTION_PLAY_PAUSE | PlaybackState.ACTION_SKIP_TO_NEXT | PlaybackState.ACTION_SKIP_TO_PREVIOUS) .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(); } }
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()); }