List of usage examples for android.media.session PlaybackState ACTION_SKIP_TO_PREVIOUS
long ACTION_SKIP_TO_PREVIOUS
To view the source code for android.media.session PlaybackState ACTION_SKIP_TO_PREVIOUS.
Click Source Link
From source file:com.example.android.mediabrowserservice.MediaNotificationManager.java
private Notification createNotification() { LogHelper.d(TAG, "updateNotificationMetadata. mMetadata=" + mMetadata); if (mMetadata == null || mPlaybackState == null) { return null; }//from ww w . j a v a 2 s . c om NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(mService); int playPauseButtonPosition = 0; // If skip to previous action is enabled if ((mPlaybackState.getActions() & PlaybackState.ACTION_SKIP_TO_PREVIOUS) != 0) { notificationBuilder.addAction(R.drawable.ic_skip_previous_white_24dp, mService.getString(R.string.label_previous), mPreviousIntent); // 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; } addPlayPauseAction(notificationBuilder); // If skip to next action is enabled if ((mPlaybackState.getActions() & PlaybackState.ACTION_SKIP_TO_NEXT) != 0) { notificationBuilder.addAction(R.drawable.ic_skip_next_white_24dp, mService.getString(R.string.label_next), mNextIntent); } MediaDescriptionCompat description = mMetadata.getDescription(); String fetchArtUrl = null; Bitmap art = null; if (description.getIconUri() != null) { // This sample assumes the iconUri will be a valid URL formatted String, but // it can actually be any valid Android Uri formatted String. // async fetch the album art icon String artUrl = description.getIconUri().toString(); art = AlbumArtCache.getInstance().getBigImage(artUrl); if (art == null) { fetchArtUrl = artUrl; // use a placeholder art while the remote art is being downloaded art = BitmapFactory.decodeResource(mService.getResources(), R.drawable.ic_default_art); } } notificationBuilder .setStyle(new NotificationCompat.MediaStyle() .setShowActionsInCompactView(new int[] { playPauseButtonPosition }) // show only play/pause in compact view .setMediaSession(mSessionToken)) .setColor(mNotificationColor).setSmallIcon(R.drawable.ic_notification) .setVisibility(Notification.VISIBILITY_PUBLIC).setUsesChronometer(true) .setContentIntent(createContentIntent()).setContentTitle(description.getTitle()) .setContentText(description.getSubtitle()).setLargeIcon(art); setNotificationPlaybackState(notificationBuilder); if (fetchArtUrl != null) { fetchBitmapFromURLAsync(fetchArtUrl, notificationBuilder); } return notificationBuilder.build(); }
From source file:com.appdevper.mediaplayer.app.MediaNotificationManager.java
private Notification createNotification() { LogHelper.d(TAG, "updateNotificationMetadata. mMetadata=" + mMetadata); if (mMetadata == null || mPlaybackState == null) { return null; }/* w w w .ja v a2s . c om*/ NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(mService); int playPauseButtonPosition = 0; // If skip to previous action is enabled if ((mPlaybackState.getActions() & PlaybackState.ACTION_SKIP_TO_PREVIOUS) != 0) { notificationBuilder.addAction(R.drawable.ic_skip_previous_white_24dp, mService.getString(R.string.label_previous), mPreviousIntent); playPauseButtonPosition = 1; } addPlayPauseAction(notificationBuilder); // If skip to next action is enabled if ((mPlaybackState.getActions() & PlaybackState.ACTION_SKIP_TO_NEXT) != 0) { notificationBuilder.addAction(R.drawable.ic_skip_next_white_24dp, mService.getString(R.string.label_next), mNextIntent); } MediaDescriptionCompat description = mMetadata.getDescription(); String fetchArtUrl = null; Bitmap art = null; if (description.getIconUri() != null) { String artUrl = description.getIconUri().toString(); art = AlbumArtCache.getInstance().getBigImage(artUrl); if (art == null) { fetchArtUrl = artUrl; art = BitmapFactory.decodeResource(mService.getResources(), R.drawable.ic_default_art); } } notificationBuilder .setStyle(new NotificationCompat.MediaStyle() .setShowActionsInCompactView(new int[] { playPauseButtonPosition }) // show only play/pause in compact view .setMediaSession(mSessionToken)) .setColor(mNotificationColor).setSmallIcon(R.drawable.ic_notification) .setVisibility(Notification.VISIBILITY_PUBLIC).setUsesChronometer(true) .setContentIntent(createContentIntent(description)).setContentTitle(description.getTitle()) .setContentText(description.getSubtitle()).setLargeIcon(art); if (mController != null && mController.getExtras() != null) { String castName = mController.getExtras().getString(MusicService.EXTRA_CONNECTED_CAST); if (castName != null) { String castInfo = mService.getResources().getString(R.string.casting_to_device, castName); notificationBuilder.setSubText(castInfo); notificationBuilder.addAction(R.drawable.ic_close_black_24dp, mService.getString(R.string.stop_casting), mStopCastIntent); } } setNotificationPlaybackState(notificationBuilder); fetchBitmapFromURLAsync(fetchArtUrl, notificationBuilder); return notificationBuilder.build(); }
From source file:de.kraenksoft.c3tv.ui.PlaybackOverlayFragment.java
private long getAvailableActions(int nextState) { long actions = PlaybackState.ACTION_PLAY | PlaybackState.ACTION_PLAY_FROM_MEDIA_ID | PlaybackState.ACTION_PLAY_FROM_SEARCH | PlaybackState.ACTION_SKIP_TO_NEXT | PlaybackState.ACTION_SKIP_TO_PREVIOUS | PlaybackState.ACTION_PAUSE; if (nextState == PlaybackState.STATE_PLAYING) { actions |= PlaybackState.ACTION_PAUSE; }/*from w ww.jav a2 s . c om*/ return actions; }
From source file:org.mythtv.android.presentation.view.fragment.TvPlaybackOverlayFragment.java
private long getAvailableActions(int nextState) { long actions = PlaybackState.ACTION_PLAY | PlaybackState.ACTION_PLAY_FROM_MEDIA_ID | PlaybackState.ACTION_PLAY_FROM_SEARCH | PlaybackState.ACTION_SKIP_TO_NEXT | PlaybackState.ACTION_SKIP_TO_PREVIOUS | PlaybackState.ACTION_PAUSE; if (nextState == PlaybackState.STATE_PLAYING) { actions |= PlaybackState.ACTION_PAUSE; }//from ww w . ja v a 2 s . co m return actions; }
From source file:com.appdevper.mediaplayer.activity.FullScreenPlayerActivity.java
private void updatePlaybackState(PlaybackStateCompat state) { if (state == null) { return;// ww w . ja v a 2s . 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); mLine3.setText(line3Text); } switch (state.getState()) { case PlaybackState.STATE_PLAYING: mLoading.setVisibility(INVISIBLE); mPlayPause.setVisibility(VISIBLE); mPlayPause.setImageDrawable(mPauseDrawable); mControllers.setVisibility(VISIBLE); scheduleSeekbarUpdate(); break; case PlaybackState.STATE_PAUSED: mControllers.setVisibility(VISIBLE); mLoading.setVisibility(INVISIBLE); mPlayPause.setVisibility(VISIBLE); mPlayPause.setImageDrawable(mPlayDrawable); stopSeekbarUpdate(); break; case PlaybackState.STATE_NONE: case PlaybackState.STATE_STOPPED: mLoading.setVisibility(INVISIBLE); mPlayPause.setVisibility(VISIBLE); mPlayPause.setImageDrawable(mPlayDrawable); stopSeekbarUpdate(); break; case PlaybackState.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() & PlaybackState.ACTION_SKIP_TO_NEXT) == 0 ? INVISIBLE : VISIBLE); mSkipPrev.setVisibility( (state.getActions() & PlaybackState.ACTION_SKIP_TO_PREVIOUS) == 0 ? INVISIBLE : VISIBLE); }
From source file:com.aengbee.android.leanback.ui.PlaybackOverlayCustomFragment.java
private long getAvailableActions(int nextState) { long actions = PlaybackState.ACTION_PLAY | PlaybackState.ACTION_PLAY_FROM_MEDIA_ID | PlaybackState.ACTION_PLAY_FROM_SEARCH | PlaybackState.ACTION_SKIP_TO_NEXT | PlaybackState.ACTION_SKIP_TO_PREVIOUS | PlaybackState.ACTION_FAST_FORWARD | PlaybackState.ACTION_REWIND | PlaybackState.ACTION_PAUSE; if (nextState == PlaybackState.STATE_PLAYING) { actions |= PlaybackState.ACTION_PAUSE; }//w w w . j a v a2s . c o m return actions; }
From source file:com.koma.music.service.MusicService.java
private void updateMediaSession(final String what) { LogUtils.i(TAG, "updateMediaSession what : " + what); int playState = mIsSupposedToBePlaying ? PlaybackState.STATE_PLAYING : PlaybackState.STATE_PAUSED; long playBackStateActions = PlaybackState.ACTION_PLAY | PlaybackState.ACTION_PLAY_PAUSE | PlaybackState.ACTION_PLAY_FROM_MEDIA_ID | PlaybackState.ACTION_PAUSE | PlaybackState.ACTION_SKIP_TO_NEXT | PlaybackState.ACTION_SKIP_TO_PREVIOUS | PlaybackState.ACTION_STOP; if (what.equals(MusicServiceConstants.PLAYSTATE_CHANGED) || what.equals(MusicServiceConstants.POSITION_CHANGED)) { mSession.setPlaybackState(new PlaybackState.Builder().setActions(playBackStateActions) .setActiveQueueItemId(getAudioId()).setState(playState, position(), 1.0f).build()); } else if (what.equals(META_CHANGED) || what.equals(MusicServiceConstants.QUEUE_CHANGED)) { LogUtils.i(TAG, "sadsadsadsad thread id : " + Thread.currentThread().getId() + "name : " + Thread.currentThread().getName()); /*if (albumArt != null) { // RemoteControlClient wants to recycle the bitmaps thrown at it, so we need // to make sure not to hand out our cache copy Bitmap.Config config = albumArt.getConfig(); if (config == null) {//from w w w.j a va2 s .c o m config = Bitmap.Config.ARGB_8888; } albumArt = albumArt.copy(config, false); }*/ /*mSession.setMetadata(new MediaMetadataCompat.Builder() .putString(MediaMetadataCompat.METADATA_KEY_ARTIST, getArtistName()) .putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ARTIST, getAlbumArtistName()) .putString(MediaMetadataCompat.METADATA_KEY_ALBUM, getAlbumName()) .putString(MediaMetadataCompat.METADATA_KEY_TITLE, getTrackName()) .putLong(MediaMetadataCompat.METADATA_KEY_DURATION, duration()) .putLong(MediaMetadataCompat.METADATA_KEY_TRACK_NUMBER, getQueuePosition() + 1) .putLong(MediaMetadataCompat.METADATA_KEY_NUM_TRACKS, getQueue().length) .putString(MediaMetadataCompat.METADATA_KEY_GENRE, getGenreName()) .putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, mShowAlbumArtOnLockscreen ? albumArt : null) .build());*/ if (what.equals(MusicServiceConstants.QUEUE_CHANGED)) { updateMediaSessionQueue(); } mSession.setPlaybackState(new PlaybackState.Builder().setActions(playBackStateActions) .setActiveQueueItemId(getAudioId()).setState(playState, position(), 1.0f).build()); } LogUtils.i(TAG, "updateMediaSession finished"); }
From source file:com.av.remusic.service.MediaService.java
private void updateMediaSession(final String what) { int playState = mIsSupposedToBePlaying ? PlaybackState.STATE_PLAYING : PlaybackState.STATE_PAUSED; if (what.equals(PLAYSTATE_CHANGED) || what.equals(POSITION_CHANGED)) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 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());//from w ww . j a v a 2 s .co m } } else if (what.equals(META_CHANGED) || what.equals(QUEUE_CHANGED)) { //Bitmap albumArt = ImageLoader.getInstance().loadImageSync(CommonUtils.getAlbumArtUri(getAlbumId()).toString()); Bitmap albumArt = null; if (albumArt != null) { Bitmap.Config config = albumArt.getConfig(); if (config == null) { config = Bitmap.Config.ARGB_8888; } albumArt = albumArt.copy(config, false); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mSession.setMetadata( new MediaMetadata.Builder().putString(MediaMetadata.METADATA_KEY_ARTIST, getArtistName()) .putString(MediaMetadata.METADATA_KEY_ALBUM_ARTIST, getAlbumArtistName()) .putString(MediaMetadata.METADATA_KEY_ALBUM, getAlbumName()) .putString(MediaMetadata.METADATA_KEY_TITLE, getTrackName()) .putLong(MediaMetadata.METADATA_KEY_DURATION, duration()) .putLong(MediaMetadata.METADATA_KEY_TRACK_NUMBER, getQueuePosition() + 1) .putLong(MediaMetadata.METADATA_KEY_NUM_TRACKS, getQueue().length) .putString(MediaMetadata.METADATA_KEY_GENRE, getGenreName()) .putBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART, mShowAlbumArtOnLockscreen ? albumArt : null) .build()); 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()); } } }