Java Code Examples for android.support.v4.media.session.PlaybackStateCompat#State
The following examples show how to use
android.support.v4.media.session.PlaybackStateCompat#State .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AudioSenseiPlayerView.java From android-audio-sensei with Apache License 2.0 | 6 votes |
@Override public void onStateChanged(@PlaybackStateCompat.State int state) { String stateToString = PlaybackInfoListener.convertStateToString(state); onLogUpdated(String.format("onStateChanged(%s)", stateToString)); if (state == State.RESET) reset(); else if (state == State.COMPLETED) { mPlayButton.setVisibility(VISIBLE); mPauseButton.setVisibility(GONE); if (mCurentDuration != null) mCurentDuration.reset(); } else if (state == State.PLAYING) { if (mCurentDuration != null) mCurentDuration.start(); } else if (state == State.PAUSED) { if (mCurentDuration != null) mCurentDuration.stop(); } }
Example 2
Source File: MediaSessionPlaybackReporter.java From PainlessMusicPlayer with Apache License 2.0 | 6 votes |
@Override public void reportPlaybackStateChanged( @NonNull final PlaybackState state, @Nullable final CharSequence errorMessage) { @PlaybackStateCompat.State final int playbackState = toPlaybackStateCompat(state); final boolean isPlaying = playbackState == PlaybackStateCompat.STATE_PLAYING; final PlaybackStateCompat.Builder builder = new PlaybackStateCompat.Builder() .setActions(PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PAUSE | PlaybackStateCompat.ACTION_PLAY_PAUSE | PlaybackStateCompat.ACTION_STOP | PlaybackStateCompat.ACTION_SKIP_TO_NEXT | PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS | PlaybackStateCompat.ACTION_SEEK_TO | PlaybackStateCompat.ACTION_PLAY_FROM_SEARCH) .setState(playbackState, 0, isPlaying ? 1 : 0); if (errorMessage != null) { builder.setErrorMessage(PlaybackStateCompat.ERROR_CODE_APP_ERROR, errorMessage); } mMediaSession.setPlaybackState(builder.build()); }
Example 3
Source File: MediaSessionPlaybackReporter.java From PainlessMusicPlayer with Apache License 2.0 | 6 votes |
@PlaybackStateCompat.State private static int toPlaybackStateCompat(@NonNull final PlaybackState state) { switch (state) { case STATE_LOADING: return PlaybackStateCompat.STATE_BUFFERING; case STATE_PLAYING: return PlaybackStateCompat.STATE_PLAYING; case STATE_PAUSED: return PlaybackStateCompat.STATE_PAUSED; case STATE_ERROR: return PlaybackStateCompat.STATE_ERROR; case STATE_IDLE: default: return PlaybackStateCompat.STATE_NONE; } }
Example 4
Source File: MediaSessionPlaybackActivity.java From media-samples with Apache License 2.0 | 5 votes |
private void updatePlaybackState( @PlaybackStateCompat.State int state, long playbackActions, int position, int mediaId) { PlaybackStateCompat.Builder builder = new PlaybackStateCompat.Builder() .setActions(playbackActions) .setActiveQueueItemId(mediaId) .setState(state, position, 1.0f); mSession.setPlaybackState(builder.build()); }
Example 5
Source File: MediaSessionPlaybackActivityTest.java From media-samples with Apache License 2.0 | 5 votes |
private void assertMediaStateIs(@PlaybackStateCompat.State int expectedState) { PlaybackState state = rule.getActivity().getMediaController().getPlaybackState(); assertNotNull(state); assertThat( "MediaSession is not in the correct state", state.getState(), is(equalTo(expectedState))); }
Example 6
Source File: PlaybackFragment.java From leanback-assistant with Apache License 2.0 | 5 votes |
private void updatePlaybackState( @PlaybackStateCompat.State int state, long position, MediaDescriptionCompat description) { PlaybackStateCompat.Builder builder = new PlaybackStateCompat.Builder() .setActions(AVAILABLE_MEDIA_ACTIONS) .setActiveQueueItemId(Long.parseLong(description.getMediaId())) .setState(state, position, 1.0f); mSession.setPlaybackState(builder.build()); }
Example 7
Source File: MediaSessionPlaybackActivity.java From android-PictureInPicture with Apache License 2.0 | 5 votes |
private void updatePlaybackState( @PlaybackStateCompat.State int state, long playbackActions, int position, int mediaId) { PlaybackStateCompat.Builder builder = new PlaybackStateCompat.Builder() .setActions(playbackActions) .setActiveQueueItemId(mediaId) .setState(state, position, 1.0f); mSession.setPlaybackState(builder.build()); }
Example 8
Source File: MediaSessionPlaybackActivityTest.java From android-PictureInPicture with Apache License 2.0 | 5 votes |
private void assertMediaStateIs(@PlaybackStateCompat.State int expectedState) { PlaybackState state = rule.getActivity().getMediaController().getPlaybackState(); assertNotNull(state); assertThat( "MediaSession is not in the correct state", state.getState(), is(equalTo(expectedState))); }
Example 9
Source File: MediaPlayerAdapter.java From android-MediaBrowserService with Apache License 2.0 | 5 votes |
private void setNewState(@PlaybackStateCompat.State int newPlayerState) { mState = newPlayerState; // Whether playback goes to completion, or whether it is stopped, the // mCurrentMediaPlayedToCompletion is set to true. if (mState == PlaybackStateCompat.STATE_STOPPED) { mCurrentMediaPlayedToCompletion = true; } // Work around for MediaPlayer.getCurrentPosition() when it changes while not playing. final long reportPosition; if (mSeekWhileNotPlaying >= 0) { reportPosition = mSeekWhileNotPlaying; if (mState == PlaybackStateCompat.STATE_PLAYING) { mSeekWhileNotPlaying = -1; } } else { reportPosition = mMediaPlayer == null ? 0 : mMediaPlayer.getCurrentPosition(); } final PlaybackStateCompat.Builder stateBuilder = new PlaybackStateCompat.Builder(); stateBuilder.setActions(getAvailableActions()); stateBuilder.setState(mState, reportPosition, 1.0f, SystemClock.elapsedRealtime()); mPlaybackInfoListener.onPlaybackStateChange(stateBuilder.build()); }
Example 10
Source File: MediaSessionPlaybackActivity.java From media-samples with Apache License 2.0 | 2 votes |
/** * Overloaded method that persists previously set media actions. * * @param state The state of the video, e.g. playing, paused, etc. * @param position The position of playback in the video. * @param mediaId The media id related to the video in the media session. */ private void updatePlaybackState( @PlaybackStateCompat.State int state, int position, int mediaId) { long actions = mSession.getController().getPlaybackState().getActions(); updatePlaybackState(state, actions, position, mediaId); }
Example 11
Source File: MediaSessionPlaybackActivity.java From android-PictureInPicture with Apache License 2.0 | 2 votes |
/** * Overloaded method that persists previously set media actions. * * @param state The state of the video, e.g. playing, paused, etc. * @param position The position of playback in the video. * @param mediaId The media id related to the video in the media session. */ private void updatePlaybackState( @PlaybackStateCompat.State int state, int position, int mediaId) { long actions = mSession.getController().getPlaybackState().getActions(); updatePlaybackState(state, actions, position, mediaId); }