Example usage for android.media.session PlaybackState getState

List of usage examples for android.media.session PlaybackState getState

Introduction

In this page you can find the example usage for android.media.session PlaybackState getState.

Prototype

@State
public int getState() 

Source Link

Document

Get the current state of playback.

Usage

From source file:com.aengbee.android.leanback.ui.PlaybackOverlayCustomFragment.java

private int getPlaybackState() {
    Activity activity = getActivity();// ww  w. j  a  v a  2 s . c om

    if (activity != null) {
        PlaybackState state = activity.getMediaController().getPlaybackState();
        if (state != null) {
            return state.getState();
        } else {
            return PlaybackState.STATE_NONE;
        }
    }
    return PlaybackState.STATE_NONE;
}

From source file:org.mythtv.android.presentation.view.fragment.TvPlaybackOverlayFragment.java

private int getPlaybackState() {

    Activity activity = getActivity();//from  w  w  w .ja v a  2s .co m

    if (activity != null) {

        PlaybackState state = activity.getMediaController().getPlaybackState();
        if (state != null) {

            return state.getState();
        } else {

            return PlaybackState.STATE_NONE;
        }
    }

    return PlaybackState.STATE_NONE;
}

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  ww . j  a va2 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);
    }
}