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:android.support.v17.leanback.media.MediaControllerAdapter.java
@Override public long getSupportedActions() { long supportedActions = 0; if (mController.getPlaybackState() == null) { return supportedActions; }//from w w w . j a va2 s . com long actionsFromController = mController.getPlaybackState().getActions(); // Translation. if ((actionsFromController & PlaybackStateCompat.ACTION_PLAY_PAUSE) != 0) { supportedActions |= ACTION_PLAY_PAUSE; } if ((actionsFromController & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) != 0) { supportedActions |= ACTION_SKIP_TO_NEXT; } if ((actionsFromController & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) != 0) { supportedActions |= ACTION_SKIP_TO_PREVIOUS; } if ((actionsFromController & PlaybackStateCompat.ACTION_FAST_FORWARD) != 0) { supportedActions |= ACTION_FAST_FORWARD; } if ((actionsFromController & PlaybackStateCompat.ACTION_REWIND) != 0) { supportedActions |= ACTION_REWIND; } if ((actionsFromController & PlaybackStateCompat.ACTION_SET_REPEAT_MODE) != 0) { supportedActions |= ACTION_REPEAT; } if ((actionsFromController & PlaybackStateCompat.ACTION_SET_SHUFFLE_MODE) != 0) { supportedActions |= ACTION_SHUFFLE; } return supportedActions; }
From source file:com.example.android.leanback.PlaybackTransportControlGlueSample.java
/** * Get supported actions from player adapter then translate it into playback state compat * related actions//from w w w. j a va 2 s.c om */ private long getPlaybackStateActions() { long supportedActions = 0L; long actionsFromPlayerAdapter = getPlayerAdapter().getSupportedActions(); if ((actionsFromPlayerAdapter & PlaybackBaseControlGlue.ACTION_SKIP_TO_PREVIOUS) != 0) { supportedActions |= PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS; } else if ((actionsFromPlayerAdapter & PlaybackBaseControlGlue.ACTION_SKIP_TO_NEXT) != 0) { supportedActions |= PlaybackStateCompat.ACTION_SKIP_TO_NEXT; } else if ((actionsFromPlayerAdapter & PlaybackBaseControlGlue.ACTION_REWIND) != 0) { supportedActions |= PlaybackStateCompat.ACTION_REWIND; } else if ((actionsFromPlayerAdapter & PlaybackBaseControlGlue.ACTION_FAST_FORWARD) != 0) { supportedActions |= PlaybackStateCompat.ACTION_FAST_FORWARD; } else if ((actionsFromPlayerAdapter & PlaybackBaseControlGlue.ACTION_PLAY_PAUSE) != 0) { supportedActions |= PlaybackStateCompat.ACTION_PLAY_PAUSE; } else if ((actionsFromPlayerAdapter & PlaybackBaseControlGlue.ACTION_REPEAT) != 0) { supportedActions |= PlaybackStateCompat.ACTION_SET_REPEAT_MODE; } else if ((actionsFromPlayerAdapter & PlaybackBaseControlGlue.ACTION_SHUFFLE) != 0) { supportedActions |= PlaybackStateCompat.ACTION_SET_SHUFFLE_MODE; } return supportedActions; }
From source file:com.andryr.musicplayer.PlaybackService.java
private void updateMediaSession(String what) { if (!mMediaSession.isActive()) { mMediaSession.setActive(true);/*from w ww . jav a2 s . c om*/ } 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 {//w w w .ja v a2 s . co 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; }/* w ww. j a v a 2 s.com*/ 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; }
From source file:com.wojtechnology.sunami.TheBrain.java
public void setProgressUI(int pos, boolean isPlaying) { int speed = isPlaying ? 1 : 0; int playState = isPlaying ? PlaybackStateCompat.STATE_PLAYING : PlaybackStateCompat.STATE_PAUSED; 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(playState, pos, speed).build(); MediaSessionCompatHelper.applyState(mSession, state); }
From source file:com.example.android.leanback.MediaSessionService.java
/** * Return supported actions related to current playback state. * Currently the return value from this function is a constant. * For demonstration purpose, the customized fast forward action and customized rewind action * are supported in our case.//w ww .j av a 2 s. co m * * @return playback state actions. */ private long getPlaybackStateActions() { long res = PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PAUSE | PlaybackStateCompat.ACTION_PLAY_PAUSE | PlaybackStateCompat.ACTION_SKIP_TO_NEXT | PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS | PlaybackStateCompat.ACTION_FAST_FORWARD | PlaybackStateCompat.ACTION_REWIND | PlaybackStateCompat.ACTION_SET_SHUFFLE_MODE | PlaybackStateCompat.ACTION_SET_REPEAT_MODE; return res; }
From source file:androidx.media.MediaSession2ImplBase.java
@Override PlaybackStateCompat getPlaybackStateCompat() { synchronized (mLock) { int state = MediaUtils2.createPlaybackStateCompatState(getPlayerState(), getBufferingState()); // TODO: Consider following missing stuff // - setCustomAction(): Fill custom layout // - setErrorMessage(): Fill error message when notifyError() is called. // - setActiveQueueItemId(): Fill here with the current media item... // - setExtra(): No idea at this moment. // TODO: generate actions from the allowed commands. long allActions = PlaybackStateCompat.ACTION_STOP | PlaybackStateCompat.ACTION_PAUSE | PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_REWIND | PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS | PlaybackStateCompat.ACTION_SKIP_TO_NEXT | PlaybackStateCompat.ACTION_FAST_FORWARD | PlaybackStateCompat.ACTION_SET_RATING | PlaybackStateCompat.ACTION_SEEK_TO | PlaybackStateCompat.ACTION_PLAY_PAUSE | PlaybackStateCompat.ACTION_PLAY_FROM_MEDIA_ID | PlaybackStateCompat.ACTION_PLAY_FROM_SEARCH | PlaybackStateCompat.ACTION_SKIP_TO_QUEUE_ITEM | PlaybackStateCompat.ACTION_PLAY_FROM_URI | PlaybackStateCompat.ACTION_PREPARE | PlaybackStateCompat.ACTION_PREPARE_FROM_MEDIA_ID | PlaybackStateCompat.ACTION_PREPARE_FROM_SEARCH | PlaybackStateCompat.ACTION_PREPARE_FROM_URI | PlaybackStateCompat.ACTION_SET_REPEAT_MODE | PlaybackStateCompat.ACTION_SET_SHUFFLE_MODE | PlaybackStateCompat.ACTION_SET_CAPTIONING_ENABLED; return new PlaybackStateCompat.Builder().setState(state, getCurrentPosition(), getPlaybackSpeed()) .setActions(allActions).setBufferedPosition(getBufferedPosition()).build(); }// ww w .j av a2 s .com }
From source file:com.techmighty.baseplayer.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 . java 2s .c om } } else if (what.equals(META_CHANGED) || what.equals(QUEUE_CHANGED)) { Bitmap albumArt = ImageLoader.getInstance() .loadImageSync(BasePlayerUtils.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.devalladolid.musictoday.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 w w .ja v a2 s.co m } } else if (what.equals(META_CHANGED) || what.equals(QUEUE_CHANGED)) { 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().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()); } } }