List of usage examples for android.support.v4.media.session PlaybackStateCompat ACTION_PAUSE
long ACTION_PAUSE
To view the source code for android.support.v4.media.session PlaybackStateCompat ACTION_PAUSE.
Click Source Link
From source file:org.gateshipone.odyssey.playbackservice.managers.PlaybackServiceStatusHelper.java
/** * Updates the Metadata from Androids MediaSession. This sets track/album and stuff * for a lockscreen image for example./*from w ww . j a v a 2s .c om*/ * * @param track Current track. * @param playbackState State of the PlaybackService. */ private void updateMetadata(TrackModel track, PlaybackService.PLAYSTATE playbackState) { if (track != null) { if (playbackState == PlaybackService.PLAYSTATE.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.getTrackName()); metaDataBuilder.putString(MediaMetadataCompat.METADATA_KEY_ALBUM, track.getTrackAlbumName()); metaDataBuilder.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, track.getTrackArtistName()); metaDataBuilder.putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ARTIST, track.getTrackArtistName()); metaDataBuilder.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE, track.getTrackName()); metaDataBuilder.putLong(MediaMetadataCompat.METADATA_KEY_TRACK_NUMBER, track.getTrackNumber()); metaDataBuilder.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, track.getTrackDuration()); mMediaSession.setMetadata(metaDataBuilder.build()); } }
From source file:com.devbrackets.android.exomedia.EMLockScreen.java
/** * Determines the available playback commands supported for the current media state * * @param mediaState The current media playback state * @return The available playback options *//*from w ww.j a va 2 s. c om*/ @PlaybackStateCompat.Actions private long getPlaybackOptions(EMNotification.NotificationMediaState mediaState) { long availableActions = PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PAUSE | PlaybackStateCompat.ACTION_PLAY_PAUSE; if (mediaState.isNextEnabled()) { availableActions |= PlaybackStateCompat.ACTION_SKIP_TO_NEXT; } if (mediaState.isPreviousEnabled()) { availableActions |= PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS; } return availableActions; }
From source file:com.devbrackets.android.playlistcore.helper.MediaControlsHelper.java
/** * Determines the available playback commands supported for the current media state * * @param mediaState The current media playback state * @return The available playback options *//*ww w . j a va 2 s . c om*/ @PlaybackStateCompat.Actions protected long getPlaybackOptions(@NonNull NotificationHelper.NotificationMediaState mediaState) { long availableActions = PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PAUSE | PlaybackStateCompat.ACTION_PLAY_PAUSE; if (mediaState.isNextEnabled()) { availableActions |= PlaybackStateCompat.ACTION_SKIP_TO_NEXT; } if (mediaState.isPreviousEnabled()) { availableActions |= PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS; } return availableActions; }
From source file:nuclei.media.playback.PlaybackManager.java
private long getAvailableActions() { long actions = PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PLAY_FROM_MEDIA_ID | PlaybackStateCompat.ACTION_PLAY_FROM_URI | PlaybackStateCompat.ACTION_PLAY_FROM_SEARCH | PlaybackStateCompat.ACTION_PREPARE | PlaybackStateCompat.ACTION_PREPARE_FROM_MEDIA_ID | PlaybackStateCompat.ACTION_PREPARE_FROM_URI | PlaybackStateCompat.ACTION_REWIND | PlaybackStateCompat.ACTION_FAST_FORWARD; if (mPlayback.isPlaying()) { actions |= PlaybackStateCompat.ACTION_PAUSE; }/*from w ww. jav a 2 s . com*/ if (mQueue != null) { if (mQueue.hasNext() || mQueue.getNextQueue() != null) actions |= PlaybackStateCompat.ACTION_SKIP_TO_NEXT; if (mQueue.hasPrevious() || mQueue.getPreviousQueue() != null) actions |= PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS; actions |= PlaybackStateCompat.ACTION_SKIP_TO_QUEUE_ITEM; } return actions; }
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; }/*from w ww .ja 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: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 w w.j a va2s .c om*/ * * @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:org.chromium.chrome.browser.media.ui.NotificationMediaPlaybackControls.java
private void updateNotification() { if (mService == null) return;/*from w w w . j a v a 2 s.c o m*/ if (mMediaNotificationInfo == null) { // Notification was hidden before we could update it. assert mNotificationBuilder == null; return; } // Android doesn't badge the icons for RemoteViews automatically when // running the app under the Work profile. if (mNotificationIcon == null) { Drawable notificationIconDrawable = ApiCompatibilityUtils.getUserBadgedIcon(mContext, R.drawable.audio_playing); mNotificationIcon = drawableToBitmap(notificationIconDrawable); } if (mNotificationBuilder == null) { mNotificationBuilder = new NotificationCompat.Builder(mContext).setSmallIcon(R.drawable.audio_playing) .setAutoCancel(false).setLocalOnly(true) .setDeleteIntent(mService.getPendingIntent(ListenerService.ACTION_STOP)); } mNotificationBuilder.setOngoing(!mMediaNotificationInfo.isPaused); mNotificationBuilder.setContentIntent(createContentIntent()); RemoteViews contentView = createContentView(); contentView.setTextViewText(R.id.title, mMediaNotificationInfo.title); contentView.setTextViewText(R.id.status, getStatus()); if (mNotificationIcon != null) { contentView.setImageViewBitmap(R.id.icon, mNotificationIcon); } else { contentView.setImageViewResource(R.id.icon, R.drawable.audio_playing); } if (mMediaNotificationInfo.isPaused) { contentView.setImageViewResource(R.id.playpause, R.drawable.ic_vidcontrol_play); contentView.setContentDescription(R.id.playpause, mPlayDescription); contentView.setOnClickPendingIntent(R.id.playpause, mService.getPendingIntent(ListenerService.ACTION_PLAY)); } else { contentView.setImageViewResource(R.id.playpause, R.drawable.ic_vidcontrol_pause); contentView.setContentDescription(R.id.playpause, mPauseDescription); contentView.setOnClickPendingIntent(R.id.playpause, mService.getPendingIntent(ListenerService.ACTION_PAUSE)); } mNotificationBuilder.setContent(contentView); mNotificationBuilder.setVisibility(mMediaNotificationInfo.isPrivate ? NotificationCompat.VISIBILITY_PRIVATE : NotificationCompat.VISIBILITY_PUBLIC); if (mMediaSession == null) { mMediaSession = new MediaSessionCompat(mContext, mContext.getString(R.string.app_name), new ComponentName(mContext.getPackageName(), MediaButtonReceiver.class.getName()), null); mMediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS); mMediaSession.setCallback(mMediaSessionCallback); mMediaSession.setActive(true); } mMediaSession.setMetadata(createMetadata()); PlaybackStateCompat.Builder playbackStateBuilder = new PlaybackStateCompat.Builder() .setActions(PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PAUSE); if (mMediaNotificationInfo.isPaused) { playbackStateBuilder.setState(PlaybackStateCompat.STATE_PAUSED, PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN, 1.0f); } else { playbackStateBuilder.setState(PlaybackStateCompat.STATE_PLAYING, PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN, 1.0f); } mMediaSession.setPlaybackState(playbackStateBuilder.build()); Notification notification = mNotificationBuilder.build(); // We keep the service as a foreground service while the media is playing. When it is not, // the service isn't stopped but is no longer in foreground, thus at a lower priority. // While the service is in foreground, the associated notification can't be swipped away. // Moving it back to background allows the user to remove the notification. if (mMediaNotificationInfo.isPaused) { mService.stopForeground(false /* removeNotification */); NotificationManagerCompat manager = NotificationManagerCompat.from(mContext); manager.notify(R.id.media_playback_notification, notification); } else { mService.startForeground(R.id.media_playback_notification, notification); } }
From source file:com.andryr.musicplayer.PlaybackService.java
private void updateMediaSession(String what) { if (!mMediaSession.isActive()) { mMediaSession.setActive(true);//from www .j av a 2s . co m } if (what.equals(PLAYSTATE_CHANGED)) { int playState = isPlaying() ? PlaybackStateCompat.STATE_PLAYING : PlaybackStateCompat.STATE_PAUSED; mMediaSession.setPlaybackState(new PlaybackStateCompat.Builder() .setState(playState, getPlayerPosition(), 1.0F) .setActions(PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PAUSE | PlaybackStateCompat.ACTION_PLAY_PAUSE | PlaybackStateCompat.ACTION_SKIP_TO_NEXT | PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) .build()); } if (what.equals(META_CHANGED)) { int largeArtSize = (int) getResources().getDimension(R.dimen.art_size); Bitmap artwork = ArtworkCache.getInstance().getCachedBitmap(getAlbumId(), largeArtSize, largeArtSize); MediaMetadataCompat.Builder builder = new MediaMetadataCompat.Builder() .putString(MediaMetadataCompat.METADATA_KEY_ARTIST, getArtistName()) .putString(MediaMetadataCompat.METADATA_KEY_ALBUM, getAlbumName()) .putString(MediaMetadataCompat.METADATA_KEY_TITLE, getSongTitle()) .putLong(MediaMetadataCompat.METADATA_KEY_DURATION, getTrackDuration()) .putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, artwork); mMediaSession.setMetadata(builder.build()); } }
From source file:com.wojtechnology.sunami.TheBrain.java
private void setMetadata(FireMixtape song) { new GetArtworkTask().execute(song); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mNotification = getLollipopNotifBuilder(true).setLargeIcon(mThumbnail).setContentTitle(song.title) .setContentText(song.artist).build(); startForeground(534, mNotification); } else {//from w ww . j ava 2 s . c o m PlaybackStateCompat state = new PlaybackStateCompat.Builder() .setActions(PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PLAY_PAUSE | PlaybackStateCompat.ACTION_PAUSE | PlaybackStateCompat.ACTION_SEEK_TO | PlaybackStateCompat.ACTION_SKIP_TO_NEXT | PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) .setState(PlaybackStateCompat.STATE_PLAYING, 0, 0.0f).build(); MediaSessionCompatHelper.applyState(mSession, state); mSession.setMetadata( new MediaMetadataCompat.Builder().putString(MediaMetadataCompat.METADATA_KEY_TITLE, song.title) .putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ARTIST, song.artist) .putLong(MediaMetadata.METADATA_KEY_DURATION, Long.parseLong(song.duration)).build()); } }
From source file:com.scooter1556.sms.lib.android.service.AudioPlayerService.java
private long getAvailableActions() { long actions = PlaybackStateCompat.ACTION_PLAY_PAUSE | PlaybackStateCompat.ACTION_PLAY_FROM_MEDIA_ID; if (mediaElementList == null || mediaElementList.isEmpty()) { return actions; }//from www . j av a 2s.c o m if (mediaState == PlaybackStateCompat.STATE_PLAYING) { actions |= PlaybackStateCompat.ACTION_PAUSE; } else { actions |= PlaybackStateCompat.ACTION_PLAY; } if (currentListPosition > 0) { actions |= PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS; } if (currentListPosition < mediaElementList.size() - 1) { actions |= PlaybackStateCompat.ACTION_SKIP_TO_NEXT; } return actions; }