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.appdevper.mediaplayer.app.MediaNotificationManager.java
private void addPlayPauseAction(NotificationCompat.Builder builder) { LogHelper.d(TAG, "updatePlayPauseAction"); String label;/* w w w .jav a 2 s . c o m*/ int icon; PendingIntent intent; if (mPlaybackState.getState() == PlaybackStateCompat.STATE_PLAYING) { label = mService.getString(R.string.label_pause); icon = R.drawable.uamp_ic_pause_white_24dp; intent = mPauseIntent; } else { label = mService.getString(R.string.label_play); icon = R.drawable.uamp_ic_play_arrow_white_24dp; intent = mPlayIntent; } builder.addAction(new NotificationCompat.Action(icon, label, intent)); }
From source file:rocks.stalin.android.app.ui.FullScreenPlayerActivity.java
private void updatePlaybackState(PlaybackStateCompat state) { if (state == null) { return;/* w w w . j a v a 2 s . c o m*/ } mLastPlaybackState = state; if (MediaControllerCompat.getMediaController(this) != null && MediaControllerCompat.getMediaController(this).getExtras() != null) { String castName = MediaControllerCompat.getMediaController(this).getExtras() .getString(MusicService.EXTRA_CONNECTED_CAST); String line3Text = castName == null ? "" : getResources().getString(R.string.casting_to_device, castName); mLine3.setText(line3Text); } switch (state.getState()) { case PlaybackStateCompat.STATE_PLAYING: mLoading.setVisibility(INVISIBLE); mPlayPause.setVisibility(VISIBLE); mPlayPause.setImageDrawable(mPauseDrawable); mControllers.setVisibility(VISIBLE); scheduleSeekbarUpdate(); break; case PlaybackStateCompat.STATE_PAUSED: mControllers.setVisibility(VISIBLE); mLoading.setVisibility(INVISIBLE); mPlayPause.setVisibility(VISIBLE); mPlayPause.setImageDrawable(mPlayDrawable); stopSeekbarUpdate(); break; case PlaybackStateCompat.STATE_NONE: case PlaybackStateCompat.STATE_STOPPED: mLoading.setVisibility(INVISIBLE); mPlayPause.setVisibility(VISIBLE); mPlayPause.setImageDrawable(mPlayDrawable); stopSeekbarUpdate(); break; case PlaybackStateCompat.STATE_BUFFERING: mPlayPause.setVisibility(INVISIBLE); mLoading.setVisibility(VISIBLE); mLine3.setText(R.string.loading); stopSeekbarUpdate(); break; default: LogHelper.d(TAG, "Unhandled state ", state.getState()); } mSkipNext.setVisibility( (state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) == 0 ? INVISIBLE : VISIBLE); mSkipPrev.setVisibility( (state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) == 0 ? INVISIBLE : VISIBLE); }
From source file:com.allthatseries.RNAudioPlayer.MediaNotificationManager.java
private void setNotificationPlaybackState(NotificationCompat.Builder builder) { if (mPlaybackState == null || !mStarted) { mService.stopForeground(true);//from w ww . ja v a2s. c o m return; } if (mPlaybackState.getState() == PlaybackStateCompat.STATE_PLAYING && mPlaybackState.getPosition() >= 0) { builder.setWhen(System.currentTimeMillis() - mPlaybackState.getPosition()).setShowWhen(true) .setUsesChronometer(true); } else { builder.setWhen(0).setShowWhen(false).setUsesChronometer(false); } // Make sure that the notification can be dismissed by the user when we are not playing: builder.setOngoing(mPlaybackState.getState() == PlaybackStateCompat.STATE_PLAYING); }
From source file:nuclei.media.playback.FallbackPlayback.java
/** * Reconfigures MediaPlayer according to audio focus settings and * starts/restarts it. This method starts/restarts the MediaPlayer * respecting the current audio focus state. So if we have focus, it will * play normally; if we don't have focus, it will either leave the * MediaPlayer paused or set it to a low volume, depending on what is * allowed by the current focus settings. This method assumes mPlayer != * null, so if you are calling it, you have to do so from a context where * you are sure this is the case.//from ww w. jav a2s . co m */ private void configMediaPlayerState() { if (!mPrepared) return; if (mAudioFocus == AUDIO_NO_FOCUS_NO_DUCK) { // If we don't have audio focus and can't duck, we have to pause, if (mState == PlaybackStateCompat.STATE_PLAYING) { pause(); } } else { // we have audio focus: if (mAudioFocus == AUDIO_NO_FOCUS_CAN_DUCK) { mMediaPlayer.setVolume(VOLUME_DUCK, VOLUME_DUCK); // we'll be relatively quiet } else { if (mMediaPlayer != null) { mMediaPlayer.setVolume(VOLUME_NORMAL, VOLUME_NORMAL); // we can be loud again } // else do something for remote client. } // If we were playing when we lost focus, we need to resume playing. if (mPlayOnFocusGain) { if (mMediaPlayer != null) { if (!mMediaPlayer.isPlaying()) { if (mCurrentPosition == mMediaPlayer.getCurrentPosition()) { mState = PlaybackStateCompat.STATE_PLAYING; mMediaPlayer.start(); } else { mState = PlaybackStateCompat.STATE_BUFFERING; mMediaPlayer.seekTo((int) mCurrentPosition); } } else { mState = PlaybackStateCompat.STATE_PLAYING; } } mPlayOnFocusGain = false; } } if (mState == PlaybackStateCompat.STATE_PLAYING) mIllegalStateRetries = 0; if (mCallback != null) { mCallback.onPlaybackStatusChanged(mState); } }
From source file:org.runbuddy.tomahawk.mediaplayers.PluginMediaPlayer.java
/** * Start playing the previously prepared {@link Query} *///from w ww . j a v a2 s . c om @Override public void play() { Log.d(TAG, "play()"); mPlayState = PlaybackStateCompat.STATE_PLAYING; handlePlayState(); }
From source file:info.tongrenlu.music.LocalPlayback.java
/** * Called when MediaPlayer has completed a seek * * @see android.media.MediaPlayer.OnSeekCompleteListener *//* www. j a v a 2 s. c o m*/ @Override public void onSeekComplete(MediaPlayer mp) { Log.d(TAG, "onSeekComplete from MediaPlayer:" + mp.getCurrentPosition()); mCurrentPosition = mp.getCurrentPosition(); if (mState == PlaybackStateCompat.STATE_BUFFERING) { mMediaPlayer.start(); mState = PlaybackStateCompat.STATE_PLAYING; } if (mCallback != null) { mCallback.onPlaybackStatusChanged(mState); } }
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. ja v a 2 s .com * * @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:nuclei.media.MediaNotificationManager.java
private void addPlayPauseAction(NotificationCompat.Builder builder) { LOG.d("updatePlayPauseAction"); CharSequence label;/*from ww w . j av a 2 s .com*/ int icon; PendingIntent intent; if (mPlaybackState.getState() == PlaybackStateCompat.STATE_PLAYING) { label = ResourceProvider.getInstance().getString(ResourceProvider.PAUSE); icon = ResourceProvider.getInstance().getDrawable(ResourceProvider.PAUSE); intent = mPauseIntent; } else { label = ResourceProvider.getInstance().getString(ResourceProvider.PLAY); icon = ResourceProvider.getInstance().getDrawable(ResourceProvider.PLAY); intent = mPlayIntent; } builder.addAction(new NotificationCompat.Action(icon, label, intent)); }
From source file:androidx.media.MediaUtils2.java
static int toPlayerState(int playbackStateCompatState) { switch (playbackStateCompatState) { case PlaybackStateCompat.STATE_ERROR: return MediaPlayerBase.PLAYER_STATE_ERROR; case PlaybackStateCompat.STATE_NONE: return MediaPlayerBase.PLAYER_STATE_IDLE; case PlaybackStateCompat.STATE_PAUSED: case PlaybackStateCompat.STATE_STOPPED: case PlaybackStateCompat.STATE_BUFFERING: // means paused for buffering. return MediaPlayerBase.PLAYER_STATE_PAUSED; case PlaybackStateCompat.STATE_FAST_FORWARDING: case PlaybackStateCompat.STATE_PLAYING: case PlaybackStateCompat.STATE_REWINDING: case PlaybackStateCompat.STATE_SKIPPING_TO_NEXT: case PlaybackStateCompat.STATE_SKIPPING_TO_PREVIOUS: case PlaybackStateCompat.STATE_SKIPPING_TO_QUEUE_ITEM: case PlaybackStateCompat.STATE_CONNECTING: // Note: there's no perfect match for this. return MediaPlayerBase.PLAYER_STATE_PLAYING; }//from w w w . java 2 s .co m return MediaPlayerBase.PLAYER_STATE_ERROR; }
From source file:com.bayapps.android.robophish.ui.FullScreenPlayerActivity.java
private void updatePlaybackState(PlaybackStateCompat state) { if (state == null) { return;/*from w ww . j a v a 2 s. c om*/ } mLastPlaybackState = state; if (getSupportMediaController() != null && getSupportMediaController().getExtras() != null) { String castName = getSupportMediaController().getExtras().getString(MusicService.EXTRA_CONNECTED_CAST); String line3Text = castName == null ? "" : getResources().getString(R.string.casting_to_device, castName); mLine5.setText(line3Text); } switch (state.getState()) { case PlaybackStateCompat.STATE_PLAYING: mLoading.setVisibility(INVISIBLE); mPlayPause.setVisibility(VISIBLE); mPlayPause.setImageDrawable(mPauseDrawable); mControllers.setVisibility(VISIBLE); scheduleSeekbarUpdate(); break; case PlaybackStateCompat.STATE_PAUSED: mControllers.setVisibility(VISIBLE); mLoading.setVisibility(INVISIBLE); mPlayPause.setVisibility(VISIBLE); mPlayPause.setImageDrawable(mPlayDrawable); stopSeekbarUpdate(); break; case PlaybackStateCompat.STATE_NONE: case PlaybackStateCompat.STATE_STOPPED: mLoading.setVisibility(INVISIBLE); mPlayPause.setVisibility(VISIBLE); mPlayPause.setImageDrawable(mPlayDrawable); stopSeekbarUpdate(); break; case PlaybackStateCompat.STATE_BUFFERING: mPlayPause.setVisibility(INVISIBLE); mLoading.setVisibility(VISIBLE); mLine5.setText(R.string.loading); stopSeekbarUpdate(); break; default: LogHelper.d(TAG, "Unhandled state ", state.getState()); } mSkipNext.setVisibility( (state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) == 0 ? INVISIBLE : VISIBLE); mSkipPrev.setVisibility( (state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) == 0 ? INVISIBLE : VISIBLE); }