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:com.bluros.music.MusicService.java
private void updateMediaSession(final String what) { int playState = mIsSupposedToBePlaying ? PlaybackStateCompat.STATE_PLAYING : PlaybackStateCompat.STATE_PAUSED; if (what.equals(PLAYSTATE_CHANGED) || what.equals(POSITION_CHANGED)) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mSession.setPlaybackState(new PlaybackStateCompat.Builder().setState(playState, position(), 1.0f) .setActions(PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PAUSE | PlaybackStateCompat.ACTION_PLAY_PAUSE | PlaybackStateCompat.ACTION_SKIP_TO_NEXT | PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) .build());/*from w ww . j a v a 2 s . com*/ } } else if (what.equals(META_CHANGED) || what.equals(QUEUE_CHANGED)) { Bitmap albumArt = ImageLoader.getInstance() .loadImageSync(MusicUtils.getAlbumArtUri(getAlbumId()).toString()); 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 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()); mSession.setPlaybackState(new PlaybackStateCompat.Builder().setState(playState, position(), 1.0f) .setActions(PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PAUSE | PlaybackStateCompat.ACTION_PLAY_PAUSE | PlaybackStateCompat.ACTION_SKIP_TO_NEXT | PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) .build()); } } }
From source file:androidx.media.widget.VideoView2.java
private void updatePlaybackState() { if (mStateBuilder == null) { /*/*from w ww . j a v a 2 s.com*/ // Get the capabilities of the player for this stream mMetadata = mMediaPlayer.getMetadata(MediaPlayer.METADATA_ALL, MediaPlayer.BYPASS_METADATA_FILTER); // Add Play action as default long playbackActions = PlaybackStateCompat.ACTION_PLAY; if (mMetadata != null) { if (!mMetadata.has(Metadata.PAUSE_AVAILABLE) || mMetadata.getBoolean(Metadata.PAUSE_AVAILABLE)) { playbackActions |= PlaybackStateCompat.ACTION_PAUSE; } if (!mMetadata.has(Metadata.SEEK_BACKWARD_AVAILABLE) || mMetadata.getBoolean(Metadata.SEEK_BACKWARD_AVAILABLE)) { playbackActions |= PlaybackStateCompat.ACTION_REWIND; } if (!mMetadata.has(Metadata.SEEK_FORWARD_AVAILABLE) || mMetadata.getBoolean(Metadata.SEEK_FORWARD_AVAILABLE)) { playbackActions |= PlaybackStateCompat.ACTION_FAST_FORWARD; } if (!mMetadata.has(Metadata.SEEK_AVAILABLE) || mMetadata.getBoolean(Metadata.SEEK_AVAILABLE)) { playbackActions |= PlaybackStateCompat.ACTION_SEEK_TO; } } else { playbackActions |= (PlaybackStateCompat.ACTION_PAUSE | PlaybackStateCompat.ACTION_REWIND | PlaybackStateCompat.ACTION_FAST_FORWARD | PlaybackStateCompat.ACTION_SEEK_TO); } */ // TODO determine the actionable list based the metadata info. long playbackActions = PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PAUSE | PlaybackStateCompat.ACTION_REWIND | PlaybackStateCompat.ACTION_FAST_FORWARD | PlaybackStateCompat.ACTION_SEEK_TO; mStateBuilder = new PlaybackStateCompat.Builder(); mStateBuilder.setActions(playbackActions); if (mCustomActionList != null) { for (PlaybackStateCompat.CustomAction action : mCustomActionList) { mStateBuilder.addCustomAction(action); } } } mStateBuilder.setState(getCorrespondingPlaybackState(), mMediaPlayer.getCurrentPosition(), mSpeed); if (mCurrentState != STATE_ERROR && mCurrentState != STATE_IDLE && mCurrentState != STATE_PREPARING) { // TODO: this should be replaced with MediaPlayer2.getBufferedPosition() once it is // implemented. if (mCurrentBufferPercentage == -1) { mStateBuilder.setBufferedPosition(-1); } else { mStateBuilder.setBufferedPosition( (long) (mCurrentBufferPercentage / 100.0 * mMediaPlayer.getDuration())); } } // Set PlaybackState for MediaSession if (mMediaSession != null) { PlaybackStateCompat state = mStateBuilder.build(); mMediaSession.setPlaybackState(state); } }
From source file:org.runbuddy.tomahawk.services.PlaybackService.java
private void updateMediaPlayState() { if (mMediaSession == null) { Log.e(TAG, "updateMediaPlayState failed - mMediaSession == null!"); return;/*from w ww . j a v a 2 s. co m*/ } long actions = 0L; if (mPlaybackManager.getCurrentQuery() != null) { actions |= PlaybackStateCompat.ACTION_SET_RATING; } if (mPlayState == PlaybackStateCompat.STATE_PLAYING) { actions |= PlaybackStateCompat.ACTION_PAUSE | PlaybackStateCompat.ACTION_SEEK_TO | PlaybackStateCompat.ACTION_FAST_FORWARD | PlaybackStateCompat.ACTION_REWIND; } else { actions |= PlaybackStateCompat.ACTION_PLAY; } if (mPlaybackManager.hasNextEntry()) { actions |= PlaybackStateCompat.ACTION_SKIP_TO_NEXT; } if (mPlaybackManager.hasPreviousEntry()) { actions |= PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS; } Log.d(TAG, "updateMediaPlayState()"); Bundle extras = new Bundle(); extras.putInt(EXTRAS_KEY_REPEAT_MODE, mPlaybackManager.getRepeatMode()); extras.putInt(EXTRAS_KEY_SHUFFLE_MODE, mPlaybackManager.getShuffleMode()); int playState = mIsPreparing ? PlaybackStateCompat.STATE_BUFFERING : mPlayState; PlaybackStateCompat playbackStateCompat = new PlaybackStateCompat.Builder().setActions(actions) .setState(playState, getPlaybackPosition(), 1f, SystemClock.elapsedRealtime()).setExtras(extras) .build(); mMediaSession.setPlaybackState(playbackStateCompat); }
From source file:com.cyanogenmod.eleven.MusicPlaybackService.java
private void updateMediaSession(final String what) { int playState = mIsSupposedToBePlaying ? PlaybackStateCompat.STATE_PLAYING : PlaybackStateCompat.STATE_PAUSED; long playBackStateActions = PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PLAY_PAUSE | PlaybackStateCompat.ACTION_PLAY_FROM_MEDIA_ID | PlaybackStateCompat.ACTION_PAUSE | PlaybackStateCompat.ACTION_SKIP_TO_NEXT | PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS; if (what.equals(PLAYSTATE_CHANGED) || what.equals(POSITION_CHANGED)) { mSession.setPlaybackState(new PlaybackStateCompat.Builder().setActions(playBackStateActions) .setState(playState, position(), 1.0f).build()); } else if (what.equals(META_CHANGED) || what.equals(QUEUE_CHANGED)) { Bitmap albumArt = getAlbumArt(false).getBitmap(); 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) { config = Bitmap.Config.ARGB_8888; }/*ww w . j a v a2s . com*/ 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()); mSession.setPlaybackState(new PlaybackStateCompat.Builder().setActions(playBackStateActions) .setState(playState, position(), 1.0f).build()); } }