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

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

Introduction

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

Prototype

long ACTION_SKIP_TO_NEXT

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

Click Source Link

Document

Indicates this session supports the next command.

Usage

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

private void updatePlaybackState(PlaybackStateCompat state) {
    if (state == null) {
        return;/*from   w  ww  . j  av  a2s. 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:org.tomahawk.tomahawk_android.utils.MediaNotification.java

private void updateNotificationMetadata() {

    try {//ww w . j  a v a  2 s . c  o  m
        Log.d(TAG, "updateNotificationMetadata. mMetadata=" + mMetadata);
        if (mMetadata == null || mPlaybackState == null) {
            return;
        }

        mNotificationBuilder = new NotificationCompat.Builder(mService);

        List<Integer> showInCompact = new ArrayList<>();

        // updateFavoriteAction();
        //            showInCompact.add(mNotificationBuilder.mActions.size());
        //            mNotificationBuilder.addAction(mFavoriteAction);

        // If skip to previous action is enabled
        if ((mPlaybackState.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) != 0) {
            NotificationCompat.Action action = new NotificationCompat.Action.Builder(
                    R.drawable.ic_player_previous_light, mService.getString(R.string.playback_previous),
                    mIntents.get(R.drawable.ic_player_previous_light)).build();
            mNotificationBuilder.addAction(action);
        }

        updatePlayPauseAction();
        showInCompact.add(mNotificationBuilder.mActions.size());
        mNotificationBuilder.addAction(mPlayPauseAction);

        // If skip to next action is enabled
        if ((mPlaybackState.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) != 0) {
            NotificationCompat.Action action = new NotificationCompat.Action.Builder(
                    R.drawable.ic_player_next_light, mService.getString(R.string.playback_next),
                    mIntents.get(R.drawable.ic_player_next_light)).build();
            showInCompact.add(mNotificationBuilder.mActions.size());
            mNotificationBuilder.addAction(action);
        }

        MediaDescriptionCompat description = mMetadata.getDescription();

        String playbackManagerId = mController.getExtras()
                .getString(PlaybackService.EXTRAS_KEY_PLAYBACKMANAGER);
        PlaybackManager playbackManager = PlaybackManager.getByKey(playbackManagerId);
        Image image = playbackManager.getCurrentQuery().getImage();
        Bitmap art = null;
        if (image != null) {
            art = MediaImageHelper.get().getMediaImageCache().get(image);
        }
        if (art == null) {
            art = MediaImageHelper.get().getCachedPlaceHolder();
        }

        mNotificationBuilder
                .setStyle(new NotificationCompat.MediaStyle()
                        .setShowActionsInCompactView(ArrayUtil.toIntArray(showInCompact))
                        .setMediaSession(mSessionToken).setShowCancelButton(true)
                        .setCancelButtonIntent(createCancelIntent()))
                .setColor(mNotificationColor).setSmallIcon(R.drawable.ic_notification)
                .setVisibility(NotificationCompat.VISIBILITY_PUBLIC).setContentIntent(createContentIntent())
                .setContentTitle(description.getTitle()).setContentText(description.getSubtitle())
                .setTicker(description.getTitle() + " - " + description.getSubtitle()).setLargeIcon(art)
                .setOngoing(false);

        updateNotificationPlaybackState();

        mService.startForeground(NOTIFICATION_ID, mNotificationBuilder.build());
        Log.d(TAG, "updateNotificationMetadata. Notification shown");

    } catch (Exception e) {

    }
}

From source file:info.tongrenlu.FullScreenPlayerActivity.java

private void updatePlaybackState(PlaybackStateCompat state) {
    if (state == null) {
        return;//from   w w w  . ja  v  a2s  . 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: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.//from   www . ja v a  2  s.com
 *
 * @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  ww . j a  va  2 s  .c  o m*/
    }
    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  w w.j  ava 2 s.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   w  w w.java2  s. c  o  m
    }
    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.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 av  a2  s  .  c o 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:com.bayapps.android.robophish.ui.FullScreenPlayerActivity.java

private void updatePlaybackState(PlaybackStateCompat state) {
    if (state == null) {
        return;/*  w ww . j ava 2 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  a  2s  .  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);
}