List of usage examples for android.support.v4.media.session PlaybackStateCompat ACTION_PLAY_PAUSE
long ACTION_PLAY_PAUSE
To view the source code for android.support.v4.media.session PlaybackStateCompat ACTION_PLAY_PAUSE.
Click Source Link
From source file:com.naman14.timber.musicplayer.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 va2 s .c om*/ } } else if (what.equals(META_CHANGED) || what.equals(QUEUE_CHANGED)) { //TODO: Replace below Image download using Picasso Bitmap albumArt = ImageLoader.getInstance() .loadImageSync(TimberUtils.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().size()) .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:android.support.v7.app.MediaRouteControllerDialog.java
private void updatePlaybackControlLayout() { if (canShowPlaybackControlLayout()) { CharSequence title = mDescription == null ? null : mDescription.getTitle(); boolean hasTitle = !TextUtils.isEmpty(title); CharSequence subtitle = mDescription == null ? null : mDescription.getSubtitle(); boolean hasSubtitle = !TextUtils.isEmpty(subtitle); boolean showTitle = false; boolean showSubtitle = false; if (mRoute.getPresentationDisplayId() != MediaRouter.RouteInfo.PRESENTATION_DISPLAY_ID_NONE) { // The user is currently casting screen. mTitleView.setText(R.string.mr_controller_casting_screen); showTitle = true;//from ww w. j a v a 2 s .co m } else if (mState == null || mState.getState() == PlaybackStateCompat.STATE_NONE) { // Show "No media selected" as we don't yet know the playback state. mTitleView.setText(R.string.mr_controller_no_media_selected); showTitle = true; } else if (!hasTitle && !hasSubtitle) { mTitleView.setText(R.string.mr_controller_no_info_available); showTitle = true; } else { if (hasTitle) { mTitleView.setText(title); showTitle = true; } if (hasSubtitle) { mSubtitleView.setText(subtitle); showSubtitle = true; } } mTitleView.setVisibility(showTitle ? View.VISIBLE : View.GONE); mSubtitleView.setVisibility(showSubtitle ? View.VISIBLE : View.GONE); if (mState != null) { boolean isPlaying = mState.getState() == PlaybackStateCompat.STATE_BUFFERING || mState.getState() == PlaybackStateCompat.STATE_PLAYING; boolean supportsPlay = (mState.getActions() & (PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PLAY_PAUSE)) != 0; boolean supportsPause = (mState.getActions() & (PlaybackStateCompat.ACTION_PAUSE | PlaybackStateCompat.ACTION_PLAY_PAUSE)) != 0; if (isPlaying && supportsPause) { mPlayPauseButton.setVisibility(View.VISIBLE); mPlayPauseButton.setImageResource( MediaRouterThemeHelper.getThemeResource(mContext, R.attr.mediaRoutePauseDrawable)); mPlayPauseButton .setContentDescription(mContext.getResources().getText(R.string.mr_controller_pause)); } else if (!isPlaying && supportsPlay) { mPlayPauseButton.setVisibility(View.VISIBLE); mPlayPauseButton.setImageResource( MediaRouterThemeHelper.getThemeResource(mContext, R.attr.mediaRoutePlayDrawable)); mPlayPauseButton .setContentDescription(mContext.getResources().getText(R.string.mr_controller_play)); } else { mPlayPauseButton.setVisibility(View.GONE); } } } }
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());// w w w .j a v a2 s . c o m } } 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: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; }//from w w w . ja v a 2 s.c om 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()); } }