List of usage examples for android.support.v4.media.session PlaybackStateCompat STATE_NONE
int STATE_NONE
To view the source code for android.support.v4.media.session PlaybackStateCompat STATE_NONE.
Click Source Link
From source file:info.tongrenlu.FullScreenPlayerActivity.java
private void updatePlaybackState(PlaybackStateCompat state) { if (state == null) { return;//w ww . j a v a 2 s. co m } Log.d(TAG, "updatePlaybackState, playback state=" + state.getState()); mLastPlaybackState = state; mLine3.setText(""); switch (state.getState()) { case PlaybackStateCompat.STATE_PLAYING: mLoading.setVisibility(View.INVISIBLE); mPlayPause.setVisibility(View.VISIBLE); // mPlayPause.setImageDrawable(mPauseDrawable); Glide.with(this).load(R.drawable.ic_pause_white_48dp).into(mPlayPause); mControllers.setVisibility(View.VISIBLE); scheduleProgressUpdate(); break; case PlaybackStateCompat.STATE_PAUSED: mControllers.setVisibility(View.VISIBLE); mLoading.setVisibility(View.INVISIBLE); mPlayPause.setVisibility(View.VISIBLE); // mPlayPause.setImageDrawable(mPlayDrawable); Glide.with(this).load(R.drawable.ic_play_arrow_white_48dp).into(mPlayPause); stopProgressUpdate(); break; case PlaybackStateCompat.STATE_NONE: case PlaybackStateCompat.STATE_STOPPED: mLoading.setVisibility(View.INVISIBLE); mPlayPause.setVisibility(View.VISIBLE); Glide.with(this).load(R.drawable.ic_play_arrow_white_48dp).into(mPlayPause); stopProgressUpdate(); break; case PlaybackStateCompat.STATE_BUFFERING: mPlayPause.setVisibility(View.INVISIBLE); mLoading.setVisibility(View.VISIBLE); mLine3.setText(R.string.loading); stopProgressUpdate(); break; default: Log.d(TAG, "Unhandled state " + state.getState()); } mSkipNext.setVisibility((state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) == 0 ? View.INVISIBLE : View.VISIBLE); mSkipPrev.setVisibility( (state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) == 0 ? View.INVISIBLE : View.VISIBLE); }
From source file:com.scooter1556.sms.lib.android.service.AudioPlayerService.java
public void clearMediaList() { mediaElementList.clear();/*from w w w. j av a2s.co m*/ currentListPosition = 0; isPaused = false; cleanupPlayer(); // Update state mediaState = PlaybackStateCompat.STATE_NONE; updatePlaybackState(); // Update listeners for (AudioPlayerListener listener : listeners) { listener.PlaylistChanged(); listener.PlaybackStateChanged(); listener.PlaylistPositionChanged(); } }
From source file:com.example.android.leanback.MediaSessionService.java
/** * Prepare the first item in the list. And setup the listener for media player. *///from w w w . j a va 2 s . c o m private void initializePlayer() { // This service can be created for multiple times, the objects will only be created when // it is null if (mPlayer != null) { return; } mPlayer = new MediaPlayer(); // Set playback state to none to create a valid playback state. So controls row can get // information about the supported actions. mMediaSession.setPlaybackState(createPlaybackStateBuilder(PlaybackStateCompat.STATE_NONE).build()); // Activate media session if (!mMediaSession.isActive()) { mMediaSession.setActive(true); } // Set up listener and audio stream type for underlying music player. mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); // set up listener when the player is prepared. mPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { mInitialized = true; // Every time when the player is prepared (when new data source is set), // all listeners will be notified to toggle the UI to "pause" status. notifyUiWhenPlayerIsPrepared(); // When media player is prepared, the callback functions will be executed to update // the meta data and playback state. onMediaSessionMetaDataChanged(); mMediaSession .setPlaybackState(createPlaybackStateBuilder(PlaybackStateCompat.STATE_PAUSED).build()); } }); // set up listener for player's error. mPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() { @Override public boolean onError(MediaPlayer mediaPlayer, int what, int extra) { if (DEBUG) { PlaybackStateCompat.Builder builder = createPlaybackStateBuilder( PlaybackStateCompat.STATE_ERROR); builder.setErrorMessage(PlaybackStateCompat.ERROR_CODE_APP_ERROR, MEDIA_PLAYER_ERROR_MESSAGE); mMediaSession.setPlaybackState(builder.build()); } return true; } }); // set up listener to respond the event when current music item is finished mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { /** * Expected Interaction Behavior: * 1. If current media item's playing speed not equal to normal speed. * * A. MEDIA_ACTION_REPEAT_ALL * a. If current media item is the last one. The first music item in the list will * be prepared, but it won't play until user press play button. * * When user press the play button, the speed will be reset to normal (1.0f) * no matter what the previous media item's playing speed is. * * b. If current media item isn't the last one, next media item will be prepared, * but it won't play. * * When user press the play button, the speed will be reset to normal (1.0f) * no matter what the previous media item's playing speed is. * * B. MEDIA_ACTION_REPEAT_ONE * Different with previous scenario, current item will go back to the start point * again and play automatically. (The reason to enable auto play here is for * testing purpose and to make sure our designed API is flexible enough to support * different situations.) * * No matter what the previous media item's playing speed is, in this situation * current media item will be replayed in normal speed. * * C. MEDIA_ACTION_REPEAT_NONE * a. If current media is the last one. The service will be closed, no music item * will be prepared to play. From the UI perspective, the progress bar will not * be reset to the starting point. * * b. If current media item isn't the last one, next media item will be prepared, * but it won't play. * * When user press the play button, the speed will be reset to normal (1.0f) * no matter what the previous media item's playing speed is. * * @param mp Object of MediaPlayer */ @Override public void onCompletion(MediaPlayer mp) { // When current media item finishes playing, always reset rewind/ fastforward state mFastForwardSpeedFactorIndex = 0; mRewindSpeedFactorIndex = 0; // Set player's playback speed back to normal mPlayer.setPlaybackParams(mPlayer.getPlaybackParams() .setSpeed(mFastForwardSpeedFactors[mFastForwardSpeedFactorIndex])); // Pause the player, and update the status accordingly. mPlayer.pause(); mMediaSession .setPlaybackState(createPlaybackStateBuilder(PlaybackStateCompat.STATE_PAUSED).build()); if (mRepeatState == MEDIA_ACTION_REPEAT_ALL && mCurrentIndex == mMediaItemList.size() - 1) { // if the repeat mode is enabled but the shuffle mode is not enabled, // will go back to the first music item to play if (mShuffleMode == PlaybackStateCompat.SHUFFLE_MODE_NONE) { mCurrentIndex = 0; } else { // Or will choose a music item from playing list randomly. mCurrentIndex = generateMediaItemIndex(); } mCurrentMediaItem = mMediaItemList.get(mCurrentIndex); // The ui will also be changed from playing state to pause state through // setDataSource() operation setDataSource(); } else if (mRepeatState == MEDIA_ACTION_REPEAT_ONE) { // Play current music item again. // The ui will stay to be "playing" status for the reason that there is no // setDataSource() function call. mPlayer.start(); mMediaSession.setPlaybackState( createPlaybackStateBuilder(PlaybackStateCompat.STATE_PLAYING).build()); } else if (mCurrentIndex < mMediaItemList.size() - 1) { if (mShuffleMode == PlaybackStateCompat.SHUFFLE_MODE_NONE) { mCurrentIndex++; } else { mCurrentIndex = generateMediaItemIndex(); } mCurrentMediaItem = mMediaItemList.get(mCurrentIndex); // The ui will also be changed from playing state to pause state through // setDataSource() operation setDataSource(); } else { // close the service when the playlist is finished // The PlaybackState will be updated to STATE_STOPPED. And onPlayComplete // callback will be called by attached glue. mMediaSession.setPlaybackState( createPlaybackStateBuilder(PlaybackStateCompat.STATE_STOPPED).build()); stopSelf(); } } }); final MediaPlayer.OnBufferingUpdateListener mOnBufferingUpdateListener = new MediaPlayer.OnBufferingUpdateListener() { @Override public void onBufferingUpdate(MediaPlayer mp, int percent) { mBufferedProgress = getDuration() * percent / 100; PlaybackStateCompat.Builder builder = createPlaybackStateBuilder( PlaybackStateCompat.STATE_BUFFERING); builder.setBufferedPosition(mBufferedProgress); mMediaSession.setPlaybackState(builder.build()); } }; mPlayer.setOnBufferingUpdateListener(mOnBufferingUpdateListener); }
From source file:nuclei.media.playback.PlaybackManager.java
/** * Switch to a different Playback instance, maintaining all playback state, if possible. * * @param playback switch to this playback *//* w ww .j ava2 s. c om*/ public void switchToPlayback(Playback playback, boolean resumePlaying) { if (playback == null) { throw new IllegalArgumentException("Playback cannot be null"); } playback.setSurface(mPlayback.getSurfaceId(), mPlayback.getSurface()); // suspend the current one. final int oldState = mPlayback.getState(); long pos = mPlayback.getCurrentStreamPosition(); if (pos < 0) pos = mPlayback.getStartStreamPosition(); mPlayback.stop(false); playback.setCallback(this); playback.setCurrentStreamPosition(pos); playback.setCurrentMediaMetadata(mPlayback.getCurrentMediaId(), mPlayback.getCurrentMetadata()); playback.start(); // finally swap the instance mPlayback = playback; switch (oldState) { case PlaybackStateCompat.STATE_BUFFERING: case PlaybackStateCompat.STATE_CONNECTING: case PlaybackStateCompat.STATE_PAUSED: mPlayback.pause(); break; case PlaybackStateCompat.STATE_PLAYING: if (resumePlaying && mMediaMetadata != null) { mPlayback.play(mMediaMetadata); } else if (!resumePlaying) { mPlayback.pause(); } else { mPlayback.stop(true); } break; case PlaybackStateCompat.STATE_NONE: break; default: } }
From source file:androidx.media.MediaUtils2.java
static int createPlaybackStateCompatState(int playerState, int bufferingState) { switch (playerState) { case MediaPlayerBase.PLAYER_STATE_PLAYING: switch (bufferingState) { case MediaPlayerBase.BUFFERING_STATE_BUFFERING_AND_STARVED: return PlaybackStateCompat.STATE_BUFFERING; }/*from w w w . j a v a 2 s .c o m*/ return PlaybackStateCompat.STATE_PLAYING; case MediaPlayerBase.PLAYER_STATE_PAUSED: return PlaybackStateCompat.STATE_PAUSED; case MediaPlayerBase.PLAYER_STATE_IDLE: return PlaybackStateCompat.STATE_NONE; case MediaPlayerBase.PLAYER_STATE_ERROR: return PlaybackStateCompat.STATE_ERROR; } // For unknown value return PlaybackStateCompat.STATE_ERROR; }
From source file:com.torrenttunes.android.ui.FullScreenPlayerActivity.java
private void updatePlaybackState(PlaybackStateCompat state) { if (state == null) { return;/*from ww w . j a v a 2 s . c om*/ } mLastPlaybackState = state; String castName = mMediaController.getExtras().getString(MusicService.EXTRA_CONNECTED_CAST); String line3Text = ""; if (castName != null) { line3Text = 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:cat.terrones.devops.radiofx.ui.FullScreenPlayerActivity.java
private void updatePlaybackState(PlaybackStateCompat state) { if (state == null) { return;/*from w w w .j a va 2s . c o m*/ } 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); 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: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 ww w . j a v a2 s.c om*/ return MediaPlayerBase.PLAYER_STATE_ERROR; }
From source file:rocks.stalin.android.app.ui.FullScreenPlayerActivity.java
private void updatePlaybackState(PlaybackStateCompat state) { if (state == null) { return;//from w w w. j a va 2s . com } 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.bayapps.android.robophish.ui.FullScreenPlayerActivity.java
private void updatePlaybackState(PlaybackStateCompat state) { if (state == null) { return;/*from w ww. j av a 2s. c o m*/ } 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); }