List of usage examples for android.support.v4.media.session PlaybackStateCompat ACTION_SKIP_TO_NEXT
long ACTION_SKIP_TO_NEXT
To view the source code for android.support.v4.media.session PlaybackStateCompat ACTION_SKIP_TO_NEXT.
Click Source Link
From source file:com.rks.musicx.services.MediaSession.java
public static void lockscreenMedia(MediaSessionCompat mediaSessionCompat, MusicXService musicXService, String what) {//from ww w.j ava 2s .c o m if (musicXService == null) { return; } MediaMetadataCompat.Builder builder = new MediaMetadataCompat.Builder(); if (what.equals(PLAYSTATE_CHANGED) || what.equals(META_CHANGED)) { int state = MediaPlayerSingleton.getInstance().getMediaPlayer().isPlaying() ? PlaybackStateCompat.STATE_PAUSED : PlaybackStateCompat.STATE_PLAYING; mediaSessionCompat.setPlaybackState(new PlaybackStateCompat.Builder() .setState(state, musicXService.getPlayerPos(), 1.0f) .setActions(PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PAUSE | PlaybackStateCompat.ACTION_PLAY_PAUSE | PlaybackStateCompat.ACTION_SKIP_TO_NEXT | PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) .build()); builder.putString(MediaMetadataCompat.METADATA_KEY_TITLE, musicXService.getsongTitle()); builder.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, musicXService.getDuration()); builder.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, musicXService.getsongArtistName()); builder.putString(MediaMetadataCompat.METADATA_KEY_ALBUM, musicXService.getsongAlbumName()); handler.post(new Runnable() { @Override public void run() { ArtworkUtils.ArtworkLoader(musicXService, 300, 300, musicXService.getsongAlbumName(), musicXService.getsongAlbumID(), new palette() { @Override public void palettework(Palette palette) { } }, new bitmap() { @Override public void bitmapwork(Bitmap bitmap) { builder.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, bitmap); mediaSessionCompat.setMetadata(builder.build()); } @Override public void bitmapfailed(Bitmap bitmap) { builder.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, bitmap); mediaSessionCompat.setMetadata(builder.build()); } }); } }); } }
From source file:com.wojtechnology.sunami.MediaSessionCompatHelper.java
private static void ensureTransportControls(MediaSessionCompat session, PlaybackStateCompat playbackState) { long actions = playbackState.getActions(); Object remoteObj = session.getRemoteControlClient(); if (actions != 0 && remoteObj != null) { int transportControls = 0; if ((actions & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) != 0) { transportControls |= RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS; }/*from www . j ava2s .co m*/ if ((actions & PlaybackStateCompat.ACTION_REWIND) != 0) { transportControls |= RemoteControlClient.FLAG_KEY_MEDIA_REWIND; } if ((actions & PlaybackStateCompat.ACTION_PLAY) != 0) { transportControls |= RemoteControlClient.FLAG_KEY_MEDIA_PLAY; } if ((actions & PlaybackStateCompat.ACTION_PLAY_PAUSE) != 0) { transportControls |= RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE; } if ((actions & PlaybackStateCompat.ACTION_PAUSE) != 0) { transportControls |= RemoteControlClient.FLAG_KEY_MEDIA_PAUSE; } if ((actions & PlaybackStateCompat.ACTION_STOP) != 0) { transportControls |= RemoteControlClient.FLAG_KEY_MEDIA_STOP; } if ((actions & PlaybackStateCompat.ACTION_FAST_FORWARD) != 0) { transportControls |= RemoteControlClient.FLAG_KEY_MEDIA_FAST_FORWARD; } if ((actions & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) != 0) { transportControls |= RemoteControlClient.FLAG_KEY_MEDIA_NEXT; } if ((actions & PlaybackStateCompat.ACTION_SEEK_TO) != 0) { transportControls |= RemoteControlClient.FLAG_KEY_MEDIA_POSITION_UPDATE; } if ((actions & PlaybackStateCompat.ACTION_SET_RATING) != 0) { transportControls |= RemoteControlClient.FLAG_KEY_MEDIA_RATING; } ((RemoteControlClient) remoteObj).setTransportControlFlags(transportControls); } }
From source file:MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); MediaSessionCompat mediaSession = new MediaSessionCompat(this, getApplication().getPackageName()); mediaSession.setCallback(mMediaSessionCallback); mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS); mediaSession.setActive(true);/*from w ww.j a v a 2 s . c om*/ PlaybackStateCompat state = new PlaybackStateCompat.Builder().setActions(PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PLAY_PAUSE | PlaybackStateCompat.ACTION_PAUSE | PlaybackStateCompat.ACTION_SKIP_TO_NEXT | PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS).build(); mediaSession.setPlaybackState(state); }
From source file:com.google.android.exoplayer2.ext.mediasession.TimelineQueueNavigator.java
@Override public long getSupportedQueueNavigatorActions(Player player) { if (player == null || player.getCurrentTimeline().getWindowCount() < 2) { return 0; }/*from w w w. j a v a 2s . c o m*/ if (player.getRepeatMode() != Player.REPEAT_MODE_OFF) { return PlaybackStateCompat.ACTION_SKIP_TO_NEXT | PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS | PlaybackStateCompat.ACTION_SKIP_TO_QUEUE_ITEM; } int currentWindowIndex = player.getCurrentWindowIndex(); long actions; if (currentWindowIndex == 0) { actions = PlaybackStateCompat.ACTION_SKIP_TO_NEXT; } else if (currentWindowIndex == player.getCurrentTimeline().getWindowCount() - 1) { actions = PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS; } else { actions = PlaybackStateCompat.ACTION_SKIP_TO_NEXT | PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS; } return actions | PlaybackStateCompat.ACTION_SKIP_TO_QUEUE_ITEM; }
From source file:net.simno.klingar.playback.PlaybackManager.java
private long getAvailableActions() { long actions = PlaybackStateCompat.ACTION_PLAY_PAUSE | PlaybackStateCompat.ACTION_PLAY_FROM_MEDIA_ID | PlaybackStateCompat.ACTION_PLAY_FROM_SEARCH | PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS | PlaybackStateCompat.ACTION_SKIP_TO_NEXT; if (playback.isPlaying()) { actions |= PlaybackStateCompat.ACTION_PAUSE; } else {//from ww w . j a v a 2 s .c o m actions |= PlaybackStateCompat.ACTION_PLAY; } return actions; }
From source file:com.doctoror.fuckoffmusicplayer.data.reporter.MediaSessionPlaybackReporter.java
@Override public void reportPlaybackStateChanged(@NonNull final PlaybackState state, @Nullable final CharSequence errorMessage) { @PlaybackStateCompat.State/*from w ww . j a v a2 s.co m*/ final int playbackState = toPlaybackStateCompat(state); final boolean isPlaying = playbackState == PlaybackStateCompat.STATE_PLAYING; final PlaybackStateCompat.Builder builder = new PlaybackStateCompat.Builder() .setActions(PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PAUSE | PlaybackStateCompat.ACTION_PLAY_PAUSE | PlaybackStateCompat.ACTION_STOP | PlaybackStateCompat.ACTION_SKIP_TO_NEXT | PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS | PlaybackStateCompat.ACTION_SEEK_TO | PlaybackStateCompat.ACTION_PLAY_FROM_SEARCH) .setState(playbackState, 0, isPlaying ? 1 : 0); if (errorMessage != null) { builder.setErrorMessage(PlaybackStateCompat.ERROR_CODE_APP_ERROR, errorMessage); } mMediaSession.setPlaybackState(builder.build()); }
From source file:com.classiqo.nativeandroid_32bitz.playback.PlaybackManager.java
private long getAvailableActions() { long actions = PlaybackStateCompat.ACTION_PLAY_PAUSE | PlaybackStateCompat.ACTION_PLAY_FROM_MEDIA_ID | PlaybackStateCompat.ACTION_PLAY_FROM_SEARCH | PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS | PlaybackStateCompat.ACTION_SKIP_TO_NEXT; if (mPlayback.isPlaying()) { actions |= PlaybackStateCompat.ACTION_PAUSE; } else {/* www . j av a 2 s .com*/ actions |= PlaybackStateCompat.ACTION_PLAY; } return actions; }
From source file:android.support.v17.leanback.media.MediaControllerGlue.java
@Override public long getSupportedActions() { long result = 0; long actions = mMediaController.getPlaybackState().getActions(); if ((actions & PlaybackStateCompat.ACTION_PLAY_PAUSE) != 0) { result |= ACTION_PLAY_PAUSE;/*from ww w . j a v a 2 s.c o m*/ } if ((actions & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) != 0) { result |= ACTION_SKIP_TO_NEXT; } if ((actions & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) != 0) { result |= ACTION_SKIP_TO_PREVIOUS; } if ((actions & PlaybackStateCompat.ACTION_FAST_FORWARD) != 0) { result |= ACTION_FAST_FORWARD; } if ((actions & PlaybackStateCompat.ACTION_REWIND) != 0) { result |= ACTION_REWIND; } return result; }
From source file:info.tongrenlu.MediaNotificationManager.java
private Notification createNotification() { TrackBean playingTrack = mService.getPlaying(); long action = mPlaybackState.getActions(); boolean canPrev = (action & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) != 0; boolean canNext = (action & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) != 0; boolean isPlaying = mPlaybackState.getState() == PlaybackStateCompat.STATE_PLAYING; Bitmap art = BitmapFactory.decodeResource(mService.getResources(), R.drawable.ic_default_art); final String artUrl = "http://files.tongrenlu.info/m" + playingTrack.getArticleId() + "/cover_400.jpg"; // RequestCreator picasso = Picasso.with(mService.getApplicationContext()) // .load(artUrl) // .placeholder(R.drawable.ic_default_art) // .resizeDimen(android.R.dimen.notification_large_icon_width, // android.R.dimen.notification_large_icon_height) // .centerCrop(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { final Notification.Builder builder = new Notification.Builder(mService); int playPauseButtonPosition = 0; if (canPrev) { builder.addAction(R.drawable.ic_skip_previous_white_24dp, mService.getString(R.string.label_previous), mPreviousPendingIntent); playPauseButtonPosition = 1; }//from ww w .ja v a 2 s . c o m if (isPlaying) { builder.addAction(R.drawable.ic_pause_white_24dp, mService.getString(R.string.label_pause), mTogglePlaybackPendingIntent); } else { builder.addAction(R.drawable.ic_play_arrow_white_24dp, mService.getString(R.string.label_play), mTogglePlaybackPendingIntent); } if (canNext) { builder.addAction(R.drawable.ic_skip_next_white_24dp, mService.getString(R.string.label_next), mNextPendingIntent); } builder.setDeleteIntent(mDeletePendingIntent); Notification.MediaStyle style = new Notification.MediaStyle(); style.setShowActionsInCompactView(playPauseButtonPosition); builder.setStyle(style).setColor(mNotificationColor).setSmallIcon(R.drawable.ic_notification) .setVisibility(Notification.VISIBILITY_PUBLIC).setContentIntent(createContentIntent()) .setContentTitle(playingTrack.getName()).setContentText(playingTrack.getAlbum()) .setLargeIcon(art).setOngoing(isPlaying).setAutoCancel(false); if (mPlaybackState == null || !mStarted) { Log.d(TAG, "updateNotificationPlaybackState. cancelling notification!"); mService.stopForeground(true); } else { if (isPlaying && mPlaybackState.getPosition() >= 0) { builder.setWhen(System.currentTimeMillis() - mPlaybackState.getPosition()); builder.setShowWhen(true); builder.setUsesChronometer(true); } else { builder.setWhen(0); builder.setShowWhen(false); builder.setUsesChronometer(false); } } // // picasso.into(new Target() { // @TargetApi(Build.VERSION_CODES.LOLLIPOP) // @Override // public void onBitmapLoaded(final Bitmap bitmap, final Picasso.LoadedFrom from) { // Log.d(TAG, "fetchBitmapFromURLAsync: set bitmap to " + artUrl); // builder.setLargeIcon(bitmap); // mNotificationManager.notify(NOTIFICATION_ID, builder.build()); // } // // @Override // public void onBitmapFailed(final Drawable errorDrawable) { // // } // // @Override // public void onPrepareLoad(final Drawable placeHolderDrawable) { // // } // }); return builder.build(); } else { final NotificationCompat.Builder builder = new NotificationCompat.Builder(mService); if (canPrev) { builder.addAction(R.drawable.ic_skip_previous_white_24dp, mService.getString(R.string.label_previous), mPreviousPendingIntent); } if (isPlaying) { builder.addAction(R.drawable.ic_pause_white_24dp, mService.getString(R.string.label_pause), mTogglePlaybackPendingIntent); } else { builder.addAction(R.drawable.ic_play_arrow_white_24dp, mService.getString(R.string.label_play), mTogglePlaybackPendingIntent); } if (canNext) { builder.addAction(R.drawable.ic_skip_next_white_24dp, mService.getString(R.string.label_next), mNextPendingIntent); } builder.setDeleteIntent(mDeletePendingIntent); builder.setColor(mNotificationColor).setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setSmallIcon(R.drawable.ic_notification).setContentIntent(createContentIntent()) .setContentTitle(playingTrack.getName()).setContentText(playingTrack.getAlbum()) .setLargeIcon(art).setOngoing(isPlaying).setAutoCancel(false); if (mPlaybackState == null || !mStarted) { mService.stopForeground(true); } else { if (isPlaying && mPlaybackState.getPosition() >= 0) { builder.setWhen(System.currentTimeMillis() - mPlaybackState.getPosition()); builder.setShowWhen(true); builder.setUsesChronometer(true); } else { builder.setWhen(0); builder.setShowWhen(false); builder.setUsesChronometer(false); } } // // picasso.into(new Target() { // @Override // public void onBitmapLoaded(final Bitmap bitmap, final Picasso.LoadedFrom from) { // Log.d(TAG, "fetchBitmapFromURLAsync: set bitmap to " + artUrl); // builder.setLargeIcon(bitmap); // mNotificationManager.notify(NOTIFICATION_ID, builder.build()); // } // // @Override // public void onBitmapFailed(final Drawable errorDrawable) { // // } // // @Override // public void onPrepareLoad(final Drawable placeHolderDrawable) { // // } // }); return builder.build(); } }
From source file:com.reallynourl.nourl.fmpfoldermusicplayer.ui.notifications.MediaNotification.java
private static void updateMediaSession(MediaSessionCompat mediaSession) { ExtendedFile currentFile = MediaManager.getInstance().getCurrentFile(); if (currentFile != null) { long validActions = PlaybackStateCompat.ACTION_STOP; if (MediaManager.getInstance().canPlay()) { validActions |= PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PAUSE; }// w ww . ja va 2s . c o m if (MediaManager.getInstance().hasNext()) { validActions |= PlaybackStateCompat.ACTION_SKIP_TO_NEXT; } if (MediaManager.getInstance().hasPrevious()) { validActions |= PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS; } int playState = MediaManager.getInstance().isPlaying() ? PlaybackStateCompat.STATE_PLAYING : PlaybackStateCompat.STATE_PAUSED; mediaSession.setMetadata(new MediaMetadataCompat.Builder() .putString(MediaMetadataCompat.METADATA_KEY_ALBUM, currentFile.getParentFile().getName()) .putString(MediaMetadataCompat.METADATA_KEY_TITLE, currentFile.getNameWithoutExtension()) .putLong(MediaMetadataCompat.METADATA_KEY_DURATION, MediaManager.getInstance().getDuration()) .putLong(MediaMetadataCompat.METADATA_KEY_TRACK_NUMBER, MediaManager.getInstance().getPlaylist().getCurrentIndex() + 1) .putLong(MediaMetadataCompat.METADATA_KEY_NUM_TRACKS, MediaManager.getInstance().getPlaylist().size()) //.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, bitmap) .build()); mediaSession.setPlaybackState(new PlaybackStateCompat.Builder() .setState(playState, MediaManager.getInstance().getPosition(), 1.0f).setActions(validActions) .build()); } else { mediaSession.setActive(false); } }