Example usage for android.support.v4.media.session PlaybackStateCompat ACTION_SKIP_TO_PREVIOUS

List of usage examples for android.support.v4.media.session PlaybackStateCompat ACTION_SKIP_TO_PREVIOUS

Introduction

In this page you can find the example usage for android.support.v4.media.session PlaybackStateCompat ACTION_SKIP_TO_PREVIOUS.

Prototype

long ACTION_SKIP_TO_PREVIOUS

To view the source code for android.support.v4.media.session PlaybackStateCompat ACTION_SKIP_TO_PREVIOUS.

Click Source Link

Document

Indicates this session supports the previous command.

Usage

From source file:github.popeen.dsub.util.compat.RemoteControlClientLP.java

protected long getPlaybackActions(boolean isSong, int currentIndex, int size) {
    long actions = PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PAUSE
            | PlaybackStateCompat.ACTION_SEEK_TO | PlaybackStateCompat.ACTION_SKIP_TO_QUEUE_ITEM;

    if (isSong) {
        if (currentIndex > 0) {
            actions |= PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS;
        }//w ww  .  j  a v  a  2s . co  m
        if (currentIndex < size - 1) {
            actions |= PlaybackStateCompat.ACTION_SKIP_TO_NEXT;
        }
    } else {
        actions |= PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS;
        actions |= PlaybackStateCompat.ACTION_SKIP_TO_NEXT;
    }

    return actions;
}

From source file:com.example.android.AudioArchive.ui.FullScreenPlayerActivity.java

private void updatePlaybackState(PlaybackStateCompat state) {
    if (state == null) {
        return;/*  w  w  w .  j a  v a 2  s . c  o m*/
    }
    if (getSupportMediaController() != null && getSupportMediaController().getExtras() != null) {
        String castName = getSupportMediaController().getExtras().getString(MusicService.EXTRA_CONNECTED_CAST);
        String line3Text = castName == null ? ""
                : getResources().getString(R.string.casting_to_device, castName);
        mLine3.setText(line3Text);
    }

    switch (state.getState()) {
    case PlaybackStateCompat.STATE_PLAYING:
        mLoading.setVisibility(INVISIBLE);
        mPlayPause.setVisibility(VISIBLE);
        mPlayPause.setImageDrawable(mPauseDrawable);
        mControllers.setVisibility(VISIBLE);

        break;
    case PlaybackStateCompat.STATE_PAUSED:
        mControllers.setVisibility(VISIBLE);
        mLoading.setVisibility(INVISIBLE);
        mPlayPause.setVisibility(VISIBLE);
        mPlayPause.setImageDrawable(mPlayDrawable);

        break;
    case PlaybackStateCompat.STATE_NONE:
    case PlaybackStateCompat.STATE_STOPPED:
        mLoading.setVisibility(INVISIBLE);
        mPlayPause.setVisibility(VISIBLE);
        mPlayPause.setImageDrawable(mPlayDrawable);

        break;
    case PlaybackStateCompat.STATE_BUFFERING:
        mPlayPause.setVisibility(INVISIBLE);
        mLoading.setVisibility(VISIBLE);
        mLine3.setText(R.string.loading);

        break;
    default:
        LogHelper.d(TAG, "Unhandled state ", state.getState());
    }

    mSkipNext.setVisibility(
            (state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) == 0 ? INVISIBLE : VISIBLE);
    mSkipPrev.setVisibility(
            (state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) == 0 ? INVISIBLE : VISIBLE);
}

From source file:info.tongrenlu.FullScreenPlayerActivity.java

private void updatePlaybackState(PlaybackStateCompat state) {
    if (state == null) {
        return;//from  www . ja  v  a  2 s.  c o  m
    }
    Log.d(TAG, "updatePlaybackState, playback state=" + state.getState());
    mLastPlaybackState = state;

    mLine3.setText("");

    switch (state.getState()) {
    case PlaybackStateCompat.STATE_PLAYING:
        mLoading.setVisibility(View.INVISIBLE);
        mPlayPause.setVisibility(View.VISIBLE);
        //                mPlayPause.setImageDrawable(mPauseDrawable);
        Glide.with(this).load(R.drawable.ic_pause_white_48dp).into(mPlayPause);
        mControllers.setVisibility(View.VISIBLE);
        scheduleProgressUpdate();
        break;
    case PlaybackStateCompat.STATE_PAUSED:
        mControllers.setVisibility(View.VISIBLE);
        mLoading.setVisibility(View.INVISIBLE);
        mPlayPause.setVisibility(View.VISIBLE);
        //                mPlayPause.setImageDrawable(mPlayDrawable);
        Glide.with(this).load(R.drawable.ic_play_arrow_white_48dp).into(mPlayPause);
        stopProgressUpdate();
        break;
    case PlaybackStateCompat.STATE_NONE:
    case PlaybackStateCompat.STATE_STOPPED:
        mLoading.setVisibility(View.INVISIBLE);
        mPlayPause.setVisibility(View.VISIBLE);
        Glide.with(this).load(R.drawable.ic_play_arrow_white_48dp).into(mPlayPause);
        stopProgressUpdate();
        break;
    case PlaybackStateCompat.STATE_BUFFERING:
        mPlayPause.setVisibility(View.INVISIBLE);
        mLoading.setVisibility(View.VISIBLE);
        mLine3.setText(R.string.loading);
        stopProgressUpdate();
        break;
    default:
        Log.d(TAG, "Unhandled state " + state.getState());
    }

    mSkipNext.setVisibility((state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) == 0 ? View.INVISIBLE
            : View.VISIBLE);
    mSkipPrev.setVisibility(
            (state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) == 0 ? View.INVISIBLE
                    : View.VISIBLE);
}

From source file:com.scooter1556.sms.android.manager.MediaNotificationManager.java

private int addActions(final NotificationCompat.Builder notificationBuilder) {
    int playPauseButtonPosition = 0;

    // If skip to previous action is enabled
    if ((playbackState.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) != 0) {
        notificationBuilder.addAction(R.drawable.ic_skip_previous_white_24dp,
                mediaService.getString(R.string.label_previous), previousIntent);

        /*/*from  w w w .j  a  v  a  2  s .  co  m*/
         * If there is a "skip to previous" button, the play/pause button will
         * be the second one. We need to keep track of it, because the MediaStyle notification
         * requires to specify the index of the buttons (actions) that should be visible
         * when in compact view.
         */
        playPauseButtonPosition = 1;
    }

    // Play or pause button, depending on the current state.
    final String label;
    final int icon;
    final PendingIntent intent;

    if (playbackState.getState() == PlaybackStateCompat.STATE_PLAYING) {
        label = mediaService.getString(R.string.label_pause);
        icon = R.drawable.ic_pause_white_24dp;
        intent = pauseIntent;
    } else {
        label = mediaService.getString(R.string.label_play);
        icon = R.drawable.ic_play_arrow_white_24dp;
        intent = playIntent;
    }

    notificationBuilder.addAction(new NotificationCompat.Action(icon, label, intent));

    // If skip to next action is enabled
    if ((playbackState.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) != 0) {
        notificationBuilder.addAction(R.drawable.ic_skip_next_white_24dp,
                mediaService.getString(R.string.label_next), nextIntent);
    }

    return playPauseButtonPosition;
}

From source file:org.gateshipone.malp.application.background.NotificationManager.java

/**
 * Updates the Metadata from Androids MediaSession. This sets track/album and stuff
 * for a lockscreen image for example./*  w  ww  . ja v a  2 s  .  c  o  m*/
 *
 * @param track         Current track.
 * @param playbackState State of the PlaybackService.
 */
private void updateMetadata(MPDTrack track, MPDCurrentStatus.MPD_PLAYBACK_STATE playbackState) {
    if (track != null) {
        if (playbackState == MPDCurrentStatus.MPD_PLAYBACK_STATE.MPD_PLAYING) {
            mMediaSession.setPlaybackState(new PlaybackStateCompat.Builder()
                    .setState(PlaybackStateCompat.STATE_PLAYING, 0, 1.0f)
                    .setActions(PlaybackStateCompat.ACTION_SKIP_TO_NEXT + PlaybackStateCompat.ACTION_PAUSE
                            + PlaybackStateCompat.ACTION_PLAY + PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS
                            + PlaybackStateCompat.ACTION_STOP + PlaybackStateCompat.ACTION_SEEK_TO)
                    .build());
        } else {
            mMediaSession.setPlaybackState(new PlaybackStateCompat.Builder()
                    .setState(PlaybackStateCompat.STATE_PAUSED, 0, 1.0f)
                    .setActions(PlaybackStateCompat.ACTION_SKIP_TO_NEXT + PlaybackStateCompat.ACTION_PAUSE
                            + PlaybackStateCompat.ACTION_PLAY + PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS
                            + PlaybackStateCompat.ACTION_STOP + PlaybackStateCompat.ACTION_SEEK_TO)
                    .build());
        }
        // Try to get old metadata to save image retrieval.
        MediaMetadataCompat oldData = mMediaSession.getController().getMetadata();
        MediaMetadataCompat.Builder metaDataBuilder;
        if (oldData == null) {
            metaDataBuilder = new MediaMetadataCompat.Builder();
        } else {
            metaDataBuilder = new MediaMetadataCompat.Builder(mMediaSession.getController().getMetadata());
        }
        metaDataBuilder.putString(MediaMetadataCompat.METADATA_KEY_TITLE, track.getTrackTitle());
        metaDataBuilder.putString(MediaMetadataCompat.METADATA_KEY_ALBUM, track.getTrackAlbum());
        metaDataBuilder.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, track.getTrackArtist());
        metaDataBuilder.putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ARTIST, track.getTrackArtist());
        metaDataBuilder.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE, track.getTrackTitle());
        metaDataBuilder.putLong(MediaMetadataCompat.METADATA_KEY_TRACK_NUMBER, track.getTrackNumber());
        metaDataBuilder.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, track.getLength());

        mMediaSession.setMetadata(metaDataBuilder.build());
    }
}

From source file:com.torrenttunes.android.ui.FullScreenPlayerActivity.java

private void updatePlaybackState(PlaybackStateCompat state) {
    if (state == null) {
        return;/*  w w  w .ja  v a2 s .com*/
    }
    mLastPlaybackState = state;
    String castName = mMediaController.getExtras().getString(MusicService.EXTRA_CONNECTED_CAST);
    String line3Text = "";
    if (castName != null) {
        line3Text = getResources().getString(R.string.casting_to_device, castName);
    }
    mLine3.setText(line3Text);

    switch (state.getState()) {
    case PlaybackStateCompat.STATE_PLAYING:
        mLoading.setVisibility(INVISIBLE);
        mPlayPause.setVisibility(VISIBLE);
        mPlayPause.setImageDrawable(mPauseDrawable);
        mControllers.setVisibility(VISIBLE);
        scheduleSeekbarUpdate();
        break;
    case PlaybackStateCompat.STATE_PAUSED:
        mControllers.setVisibility(VISIBLE);
        mLoading.setVisibility(INVISIBLE);
        mPlayPause.setVisibility(VISIBLE);
        mPlayPause.setImageDrawable(mPlayDrawable);
        stopSeekbarUpdate();
        break;
    case PlaybackStateCompat.STATE_NONE:
    case PlaybackStateCompat.STATE_STOPPED:
        mLoading.setVisibility(INVISIBLE);
        mPlayPause.setVisibility(VISIBLE);
        mPlayPause.setImageDrawable(mPlayDrawable);
        stopSeekbarUpdate();
        break;
    case PlaybackStateCompat.STATE_BUFFERING:
        mPlayPause.setVisibility(INVISIBLE);
        mLoading.setVisibility(VISIBLE);
        mLine3.setText(R.string.loading);
        stopSeekbarUpdate();
        break;
    default:
        LogHelper.d(TAG, "Unhandled state ", state.getState());
    }

    mSkipNext.setVisibility(
            (state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) == 0 ? INVISIBLE : VISIBLE);
    mSkipPrev.setVisibility(
            (state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) == 0 ? INVISIBLE : VISIBLE);
}

From source file:cat.terrones.devops.radiofx.ui.FullScreenPlayerActivity.java

private void updatePlaybackState(PlaybackStateCompat state) {
    if (state == null) {
        return;/*w  ww  .jav a 2s .  c o  m*/
    }
    mLastPlaybackState = state;
    if (getSupportMediaController() != null && getSupportMediaController().getExtras() != null) {
        String castName = getSupportMediaController().getExtras().getString(MusicService.EXTRA_CONNECTED_CAST);
        String line3Text = castName == null ? ""
                : getResources().getString(R.string.casting_to_device, castName);
        mLine3.setText(line3Text);
    }

    switch (state.getState()) {
    case PlaybackStateCompat.STATE_PLAYING:
        mLoading.setVisibility(INVISIBLE);
        mPlayPause.setVisibility(VISIBLE);
        mPlayPause.setImageDrawable(mPauseDrawable);
        mControllers.setVisibility(VISIBLE);
        scheduleSeekbarUpdate();
        break;
    case PlaybackStateCompat.STATE_PAUSED:
        mControllers.setVisibility(VISIBLE);
        mLoading.setVisibility(INVISIBLE);
        mPlayPause.setVisibility(VISIBLE);
        mPlayPause.setImageDrawable(mPlayDrawable);
        stopSeekbarUpdate();
        break;
    case PlaybackStateCompat.STATE_NONE:
    case PlaybackStateCompat.STATE_STOPPED:
        mLoading.setVisibility(INVISIBLE);
        mPlayPause.setVisibility(VISIBLE);
        mPlayPause.setImageDrawable(mPlayDrawable);
        stopSeekbarUpdate();
        break;
    case PlaybackStateCompat.STATE_BUFFERING:
        mPlayPause.setVisibility(INVISIBLE);
        mLoading.setVisibility(VISIBLE);
        mLine3.setText(R.string.loading);
        stopSeekbarUpdate();
        break;
    default:
        LogHelper.d(TAG, "Unhandled state ", state.getState());
    }

    mSkipNext.setVisibility(
            (state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) == 0 ? INVISIBLE : VISIBLE);
    mSkipPrev.setVisibility(
            (state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) == 0 ? INVISIBLE : VISIBLE);
}

From source file:rocks.stalin.android.app.ui.FullScreenPlayerActivity.java

private void updatePlaybackState(PlaybackStateCompat state) {
    if (state == null) {
        return;//from   www. j a  v  a  2s .c om
    }
    mLastPlaybackState = state;
    if (MediaControllerCompat.getMediaController(this) != null
            && MediaControllerCompat.getMediaController(this).getExtras() != null) {
        String castName = MediaControllerCompat.getMediaController(this).getExtras()
                .getString(MusicService.EXTRA_CONNECTED_CAST);
        String line3Text = castName == null ? ""
                : getResources().getString(R.string.casting_to_device, castName);
        mLine3.setText(line3Text);
    }

    switch (state.getState()) {
    case PlaybackStateCompat.STATE_PLAYING:
        mLoading.setVisibility(INVISIBLE);
        mPlayPause.setVisibility(VISIBLE);
        mPlayPause.setImageDrawable(mPauseDrawable);
        mControllers.setVisibility(VISIBLE);
        scheduleSeekbarUpdate();
        break;
    case PlaybackStateCompat.STATE_PAUSED:
        mControllers.setVisibility(VISIBLE);
        mLoading.setVisibility(INVISIBLE);
        mPlayPause.setVisibility(VISIBLE);
        mPlayPause.setImageDrawable(mPlayDrawable);
        stopSeekbarUpdate();
        break;
    case PlaybackStateCompat.STATE_NONE:
    case PlaybackStateCompat.STATE_STOPPED:
        mLoading.setVisibility(INVISIBLE);
        mPlayPause.setVisibility(VISIBLE);
        mPlayPause.setImageDrawable(mPlayDrawable);
        stopSeekbarUpdate();
        break;
    case PlaybackStateCompat.STATE_BUFFERING:
        mPlayPause.setVisibility(INVISIBLE);
        mLoading.setVisibility(VISIBLE);
        mLine3.setText(R.string.loading);
        stopSeekbarUpdate();
        break;
    default:
        LogHelper.d(TAG, "Unhandled state ", state.getState());
    }

    mSkipNext.setVisibility(
            (state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) == 0 ? INVISIBLE : VISIBLE);
    mSkipPrev.setVisibility(
            (state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) == 0 ? INVISIBLE : VISIBLE);
}

From source file:com.bayapps.android.robophish.ui.FullScreenPlayerActivity.java

private void updatePlaybackState(PlaybackStateCompat state) {
    if (state == null) {
        return;/* ww w . j a v  a2  s .  co m*/
    }
    mLastPlaybackState = state;
    if (getSupportMediaController() != null && getSupportMediaController().getExtras() != null) {
        String castName = getSupportMediaController().getExtras().getString(MusicService.EXTRA_CONNECTED_CAST);
        String line3Text = castName == null ? ""
                : getResources().getString(R.string.casting_to_device, castName);
        mLine5.setText(line3Text);
    }

    switch (state.getState()) {
    case PlaybackStateCompat.STATE_PLAYING:
        mLoading.setVisibility(INVISIBLE);
        mPlayPause.setVisibility(VISIBLE);
        mPlayPause.setImageDrawable(mPauseDrawable);
        mControllers.setVisibility(VISIBLE);
        scheduleSeekbarUpdate();
        break;
    case PlaybackStateCompat.STATE_PAUSED:
        mControllers.setVisibility(VISIBLE);
        mLoading.setVisibility(INVISIBLE);
        mPlayPause.setVisibility(VISIBLE);
        mPlayPause.setImageDrawable(mPlayDrawable);
        stopSeekbarUpdate();
        break;
    case PlaybackStateCompat.STATE_NONE:
    case PlaybackStateCompat.STATE_STOPPED:
        mLoading.setVisibility(INVISIBLE);
        mPlayPause.setVisibility(VISIBLE);
        mPlayPause.setImageDrawable(mPlayDrawable);
        stopSeekbarUpdate();
        break;
    case PlaybackStateCompat.STATE_BUFFERING:
        mPlayPause.setVisibility(INVISIBLE);
        mLoading.setVisibility(VISIBLE);
        mLine5.setText(R.string.loading);
        stopSeekbarUpdate();
        break;
    default:
        LogHelper.d(TAG, "Unhandled state ", state.getState());
    }

    mSkipNext.setVisibility(
            (state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) == 0 ? INVISIBLE : VISIBLE);
    mSkipPrev.setVisibility(
            (state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) == 0 ? INVISIBLE : VISIBLE);
}

From source file:com.murati.oszk.audiobook.ui.FullScreenPlayerActivity.java

private void updatePlaybackState(PlaybackStateCompat state) {
    if (state == null) {
        return;//  w  w  w  . j a v a2  s. com
    }

    //TODO: Fix Time for current state

    mLastPlaybackState = state;
    MediaControllerCompat controllerCompat = MediaControllerCompat
            .getMediaController(FullScreenPlayerActivity.this);
    if (controllerCompat != null && controllerCompat.getExtras() != null) {
        String castName = controllerCompat.getExtras().getString(MusicService.EXTRA_CONNECTED_CAST);
        String line3Text = castName == null ? ""
                : getResources().getString(R.string.casting_to_device, castName);
        mLine3.setText(line3Text);
    }

    switch (state.getState()) {
    case PlaybackStateCompat.STATE_PLAYING:
        mLoading.setVisibility(INVISIBLE);
        mPlayPause.setVisibility(VISIBLE);
        mPlayPause.setImageDrawable(mPauseDrawable);
        mControllers.setVisibility(VISIBLE);
        scheduleSeekbarUpdate();
        break;
    case PlaybackStateCompat.STATE_PAUSED:
        mControllers.setVisibility(VISIBLE);
        mLoading.setVisibility(INVISIBLE);
        mPlayPause.setVisibility(VISIBLE);
        mPlayPause.setImageDrawable(mPlayDrawable);
        stopSeekbarUpdate();
        break;
    case PlaybackStateCompat.STATE_NONE:
    case PlaybackStateCompat.STATE_STOPPED:
        mLoading.setVisibility(INVISIBLE);
        mPlayPause.setVisibility(VISIBLE);
        mPlayPause.setImageDrawable(mPlayDrawable);
        stopSeekbarUpdate();
        break;
    case PlaybackStateCompat.STATE_BUFFERING:
        mPlayPause.setVisibility(INVISIBLE);
        mLoading.setVisibility(VISIBLE);
        mLine3.setText(R.string.loading);
        stopSeekbarUpdate();
        break;
    default:
        LogHelper.d(TAG, "Unhandled state ", state.getState());
    }

    mSkipNext.setVisibility(
            (state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) == 0 ? INVISIBLE : VISIBLE);
    mSkipPrev.setVisibility(
            (state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) == 0 ? INVISIBLE : VISIBLE);
}