List of usage examples for android.media.session MediaController getPlaybackState
public @Nullable PlaybackState getPlaybackState()
From source file:org.opensilk.music.playback.service.PlaybackService.java
void handleIntentCommand(@NonNull Intent intent) { final String action = intent.getAction(); final String command = SERVICECMD.equals(action) ? intent.getStringExtra(CMDNAME) : null; Timber.v("handleIntentCommand: action = %s, command = %s", action, command); MediaController controller = mMediaSession.getController(); MediaController.TransportControls controls = controller.getTransportControls(); PlaybackState state = controller.getPlaybackState(); if (CMDNEXT.equals(command) || NEXT_ACTION.equals(action)) { controls.skipToNext();//from w w w.java 2 s. c o m } else if (CMDPREVIOUS.equals(command) || PREVIOUS_ACTION.equals(action)) { if (state == null || state.getPosition() < REWIND_INSTEAD_PREVIOUS_THRESHOLD) { controls.skipToPrevious(); } else { controls.seekTo(0); //TODO might need play } } else if (CMDTOGGLEPAUSE.equals(command) || TOGGLEPAUSE_ACTION.equals(action)) { if (state == null || state.getState() != PlaybackState.STATE_PLAYING) { controls.pause(); } else { controls.play(); } } else if (CMDPAUSE.equals(command) || PAUSE_ACTION.equals(action)) { controls.pause(); } else if (CMDPLAY.equals(command)) { controls.play(); } else if (CMDSTOP.equals(command) || STOP_ACTION.equals(action)) { controls.stop(); } else if (REPEAT_ACTION.equals(action)) { controls.sendCustomAction(CMD.CYCLE_REPEAT, null); } else if (SHUFFLE_ACTION.equals(action)) { controls.sendCustomAction(CMD.SHUFFLE_QUEUE, null); } }