List of usage examples for android.support.v4.media.session PlaybackStateCompat STATE_PLAYING
int STATE_PLAYING
To view the source code for android.support.v4.media.session PlaybackStateCompat STATE_PLAYING.
Click Source Link
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 w w .j av a 2 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; }//from w w w . j a va2 s. 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; }
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.scooter1556.sms.android.fragment.tv.TvVideoPlayerFragment.java
@Override public void pause() { Log.d(TAG, "pause()"); if (playbackState == PlaybackStateCompat.STATE_PLAYING) { // Pause media player and cancel the 'foreground service' state. if (mediaPlayer != null && mediaPlayer.getPlayWhenReady()) { mediaPlayer.setPlayWhenReady(false); currentPosition = mediaPlayer.getCurrentPosition(); playbackState = PlaybackStateCompat.STATE_PAUSED; }//from w ww . ja v a 2 s. c o m // While paused, retain the Media Player but give up audio focus relaxResources(false); } if (callback != null) { callback.onPlaybackStatusChanged(playbackState); } }
From source file:nuclei.media.playback.FallbackPlayback.java
@Override public void setPlaybackParams(PlaybackParameters playbackParams) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (mMediaPlayer == null || !mPrepared) { mPlaybackParams = new PlaybackParams().setSpeed(playbackParams.speed) .setPitch(playbackParams.pitch); } else {//from ww w . j a v a 2 s. c om mMediaPlayer.setPlaybackParams( new PlaybackParams().setSpeed(playbackParams.speed).setPitch(playbackParams.pitch)); if (mState != PlaybackStateCompat.STATE_PLAYING && mMediaPlayer.isPlaying()) { mState = PlaybackStateCompat.STATE_PLAYING; } if (mCallback != null) { mCallback.onPlaybackStatusChanged(mState); } } } }
From source file:com.scooter1556.sms.lib.android.service.AudioPlayerService.java
public void start() { if (mediaState == PlaybackStateCompat.STATE_STOPPED) { play();/*from ww w. j a va2 s.c o m*/ } else if (mediaState == PlaybackStateCompat.STATE_PAUSED) { player.start(); // Update state mediaState = PlaybackStateCompat.STATE_PLAYING; updatePlaybackState(); wakeLock.acquire(); wifiLock.acquire(); } isPaused = false; // Update listeners for (AudioPlayerListener listener : listeners) { listener.PlaybackStateChanged(); } }
From source file:org.chromium.chrome.browser.media.ui.MediaNotificationManager.java
private void updateMediaSession() { if (!mMediaNotificationInfo.supportsPlayPause()) return;// w w w .ja v a 2 s. c om if (mMediaSession == null) mMediaSession = createMediaSession(); try { // Tell the MediaRouter about the session, so that Chrome can control the volume // on the remote cast device (if any). // Pre-MR1 versions of JB do not have the complete MediaRouter APIs, // so getting the MediaRouter instance will throw an exception. MediaRouter.getInstance(mContext).setMediaSessionCompat(mMediaSession); } catch (NoSuchMethodError e) { // Do nothing. Chrome can't be casting without a MediaRouter, so there is nothing // to do here. } 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 { // If notification only supports stop, still pretend playbackStateBuilder.setState(PlaybackStateCompat.STATE_PLAYING, PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN, 1.0f); } mMediaSession.setPlaybackState(playbackStateBuilder.build()); }
From source file:nuclei.media.playback.ExoPlayerPlayback.java
@Override public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { if (LOG.isLoggable(Log.DEBUG)) LOG.d("onStateChanged=" + playbackState + ", " + playWhenReady); if (!mPrepared && playbackState == ExoPlayer.STATE_READY && mMediaPlayer != null) { mPrepared = true;/*from w ww . j a v a2 s .c om*/ if (!mWakeLock.isHeld()) mWakeLock.acquire(); if (!mWifiLock.isHeld()) mWifiLock.acquire(); configMediaPlayerState(true, false); setSurface(mSurfaceId, mSurface); mMediaPlayer.seekTo(mCurrentPosition); mMediaPlayer.setPlayWhenReady(mPlayWhenReady); } else if (mMediaPlayer != null && mState != PlaybackStateCompat.STATE_ERROR && mState != PlaybackStateCompat.STATE_BUFFERING) mCurrentPosition = mMediaPlayer.getCurrentPosition(); if (mMediaPlayer != null && mMediaMetadata != null) { final long duration = getDuration(); if (mMediaMetadata.getLong(MediaMetadataCompat.METADATA_KEY_DURATION) != duration) mMediaMetadata.setDuration(duration); } switch (playbackState) { case ExoPlayer.STATE_BUFFERING: mState = PlaybackStateCompat.STATE_BUFFERING; mIllegalStateRetries = 0; break; case ExoPlayer.STATE_ENDED: mState = PlaybackStateCompat.STATE_NONE; mIllegalStateRetries = 0; break; case ExoPlayer.STATE_IDLE: if (mState != PlaybackStateCompat.STATE_ERROR) mState = PlaybackStateCompat.STATE_NONE; break; case ExoPlayer.STATE_READY: mIllegalStateRetries = 0; if (isMediaPlayerPlaying()) { mState = PlaybackStateCompat.STATE_PLAYING; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (mPlaybackParams != null) mMediaPlayer.setPlaybackParameters(mPlaybackParams); } } else mState = PlaybackStateCompat.STATE_PAUSED; break; default: mState = PlaybackStateCompat.STATE_NONE; break; } if (mCallback != null) mCallback.onPlaybackStatusChanged(mState); if (playbackState == ExoPlayer.STATE_ENDED) { mRestart = true; if (mCallback != null) mCallback.onCompletion(); } }
From source file:androidx.media.widget.MediaControlView2.java
private boolean isPlaying() { if (mPlaybackState != null) { return mPlaybackState.getState() == PlaybackStateCompat.STATE_PLAYING; }//from w ww . ja va 2 s . c o m return false; }
From source file:com.scooter1556.sms.lib.android.service.AudioPlayerService.java
@Override public void onStateChanged(SMSAudioPlayer player, boolean playWhenReady, int playbackState) { switch (playbackState) { case ExoPlayer.STATE_BUFFERING: // Update state mediaState = PlaybackStateCompat.STATE_BUFFERING; updatePlaybackState();/*from w w w . j a v a 2 s. c o m*/ break; case ExoPlayer.STATE_ENDED: // Clean-up resources cleanupPlayer(); if (mediaElementList.size() > (currentListPosition + 1)) { currentListPosition++; initialiseTrack(currentListPosition); // Update state mediaState = PlaybackStateCompat.STATE_SKIPPING_TO_NEXT; updatePlaybackState(); } else { // Playlist has ended cleanupPlayer(); currentListPosition = 0; // Update state mediaState = PlaybackStateCompat.STATE_STOPPED; updatePlaybackState(); } // Update listeners for (AudioPlayerListener listener : listeners) { listener.PlaybackStateChanged(); listener.PlaylistPositionChanged(); } break; case ExoPlayer.STATE_IDLE: break; case ExoPlayer.STATE_PREPARING: // Update state mediaState = PlaybackStateCompat.STATE_CONNECTING; updatePlaybackState(); break; case ExoPlayer.STATE_READY: if (playWhenReady) { // Update state mediaState = PlaybackStateCompat.STATE_PLAYING; updatePlaybackState(); } break; default: break; } }