List of usage examples for android.media.session PlaybackState STATE_PLAYING
int STATE_PLAYING
To view the source code for android.media.session PlaybackState STATE_PLAYING.
Click Source Link
From source file:hkapps.playmxtv.Activities.PlaybackOverlayActivity.java
private void updatePlaybackState(int position) { PlaybackState.Builder stateBuilder = new PlaybackState.Builder() .setActions(PlaybackState.ACTION_PLAY_PAUSE); int state = PlaybackState.STATE_PLAYING; if (mPlaybackState == LeanbackPlaybackState.PAUSED) { state = PlaybackState.STATE_PAUSED; }// w w w . j a v a 2 s .c om stateBuilder.setState(state, position, 1.0f); mSession.setPlaybackState(stateBuilder.build()); }
From source file:com.appdevper.mediaplayer.app.LocalPlayback.java
@Override public void pause() { if (mState == PlaybackState.STATE_PLAYING) { // Pause media player and cancel the 'foreground service' state. if (mMediaPlayer != null && mMediaPlayer.isPlaying()) { mMediaPlayer.pause();/*from ww w.j av a 2 s .c o m*/ mCurrentPosition = mMediaPlayer.getCurrentPosition(); } // while paused, retain the MediaPlayer but give up audio focus relaxResources(false); giveUpAudioFocus(); } mState = PlaybackState.STATE_PAUSED; if (mCallback != null) { mCallback.onPlaybackStatusChanged(mState); } unregisterAudioNoisyReceiver(); }
From source file:com.example.android.mediabrowserservice.QueueFragment.java
private void onPlaybackStateChanged(PlaybackStateCompat state) { LogHelper.d(TAG, "onPlaybackStateChanged ", state); if (state == null) { return;//from w w w. j a va 2 s .co m } mQueueAdapter.setActiveQueueItemId(state.getActiveQueueItemId()); mQueueAdapter.notifyDataSetChanged(); boolean enablePlay = false; StringBuilder statusBuilder = new StringBuilder(); switch (state.getState()) { case PlaybackState.STATE_PLAYING: statusBuilder.append("playing"); enablePlay = false; break; case PlaybackState.STATE_PAUSED: statusBuilder.append("paused"); enablePlay = true; break; case PlaybackState.STATE_STOPPED: statusBuilder.append("ended"); enablePlay = true; break; case PlaybackState.STATE_ERROR: statusBuilder.append("error: ").append(state.getErrorMessage()); break; case PlaybackState.STATE_BUFFERING: statusBuilder.append("buffering"); break; case PlaybackState.STATE_NONE: statusBuilder.append("none"); enablePlay = false; break; case PlaybackState.STATE_CONNECTING: statusBuilder.append("connecting"); break; default: statusBuilder.append(mPlaybackState); } statusBuilder.append(" -- At position: ").append(state.getPosition()); LogHelper.d(TAG, statusBuilder.toString()); if (enablePlay) { mPlayPause.setImageDrawable( ContextCompat.getDrawable(getActivity(), R.drawable.ic_play_arrow_white_24dp)); } else { mPlayPause.setImageDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.ic_pause_white_24dp)); } mSkipPrevious.setEnabled((state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) != 0); mSkipNext.setEnabled((state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) != 0); LogHelper.d(TAG, "Queue From MediaController *** Title " + mMediaController.getQueueTitle() + "\n: Queue: " + mMediaController.getQueue() + "\n Metadata " + mMediaController.getMetadata()); }
From source file:com.appdevper.mediaplayer.activity.FullScreenPlayerActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_full_player); initializeToolbar();// w w w.j a va 2 s . c o m if (getSupportActionBar() != null) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setTitle(""); } mBackgroundImage = (ImageView) findViewById(R.id.background_image); mPauseDrawable = ContextCompat.getDrawable(this, R.drawable.uamp_ic_pause_white_48dp); mPlayDrawable = ContextCompat.getDrawable(this, R.drawable.uamp_ic_play_arrow_white_48dp); mPlayPause = (ImageView) findViewById(R.id.play_pause); mSkipNext = (ImageView) findViewById(R.id.next); mSkipPrev = (ImageView) findViewById(R.id.prev); mStart = (TextView) findViewById(R.id.startText); mEnd = (TextView) findViewById(R.id.endText); mSeekbar = (SeekBar) findViewById(R.id.seekBar1); mLine1 = (TextView) findViewById(R.id.line1); mLine2 = (TextView) findViewById(R.id.line2); mLine3 = (TextView) findViewById(R.id.line3); mLoading = (ProgressBar) findViewById(R.id.progressBar1); mControllers = findViewById(R.id.controllers); mSkipNext.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { MediaControllerCompat.TransportControls controls = getSupportMediaController() .getTransportControls(); controls.skipToNext(); } }); mSkipPrev.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { MediaControllerCompat.TransportControls controls = getSupportMediaController() .getTransportControls(); controls.skipToPrevious(); } }); mPlayPause.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { PlaybackStateCompat state = getSupportMediaController().getPlaybackState(); if (state != null) { MediaControllerCompat.TransportControls controls = getSupportMediaController() .getTransportControls(); switch (state.getState()) { case PlaybackState.STATE_PLAYING: // fall through case PlaybackState.STATE_BUFFERING: controls.pause(); stopSeekbarUpdate(); break; case PlaybackState.STATE_PAUSED: case PlaybackState.STATE_STOPPED: controls.play(); scheduleSeekbarUpdate(); break; default: LogHelper.d(TAG, "onClick with state ", state.getState()); } } } }); mSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { mStart.setText(Utils.formatMillis(progress)); } @Override public void onStartTrackingTouch(SeekBar seekBar) { stopSeekbarUpdate(); } @Override public void onStopTrackingTouch(SeekBar seekBar) { getSupportMediaController().getTransportControls().seekTo(seekBar.getProgress()); scheduleSeekbarUpdate(); } }); // Only update from the intent if we are not recreating from a config change: if (savedInstanceState == null) { updateFromParams(getIntent()); } }
From source file:org.opensilk.music.playback.service.PlaybackService.java
void handleIntentCommand(@NonNull Intent intent) { final String action = intent.getAction(); final String command = SERVICECMD.equals(action) ? intent.getStringExtra(CMDNAME) : null; Timber.v("handleIntentCommand: action = %s, command = %s", action, command); MediaController controller = mMediaSession.getController(); MediaController.TransportControls controls = controller.getTransportControls(); PlaybackState state = controller.getPlaybackState(); if (CMDNEXT.equals(command) || NEXT_ACTION.equals(action)) { controls.skipToNext();/*from www .j av a 2 s. c o m*/ } else if (CMDPREVIOUS.equals(command) || PREVIOUS_ACTION.equals(action)) { if (state == null || state.getPosition() < REWIND_INSTEAD_PREVIOUS_THRESHOLD) { controls.skipToPrevious(); } else { controls.seekTo(0); //TODO might need play } } else if (CMDTOGGLEPAUSE.equals(command) || TOGGLEPAUSE_ACTION.equals(action)) { if (state == null || state.getState() != PlaybackState.STATE_PLAYING) { controls.pause(); } else { controls.play(); } } else if (CMDPAUSE.equals(command) || PAUSE_ACTION.equals(action)) { controls.pause(); } else if (CMDPLAY.equals(command)) { controls.play(); } else if (CMDSTOP.equals(command) || STOP_ACTION.equals(action)) { controls.stop(); } else if (REPEAT_ACTION.equals(action)) { controls.sendCustomAction(CMD.CYCLE_REPEAT, null); } else if (SHUFFLE_ACTION.equals(action)) { controls.sendCustomAction(CMD.SHUFFLE_QUEUE, null); } }
From source file:com.example.android.supportv4.media.Playback.java
public void pause() { if (mState == PlaybackState.STATE_PLAYING) { // Pause media player and cancel the 'foreground service' state. if (mMediaPlayer != null && mMediaPlayer.isPlaying()) { mMediaPlayer.pause();/*from w w w. jav a2s .c om*/ mCurrentPosition = mMediaPlayer.getCurrentPosition(); } // while paused, retain the MediaPlayer but give up audio focus relaxResources(false); giveUpAudioFocus(); } mState = PlaybackState.STATE_PAUSED; if (mCallback != null) { mCallback.onPlaybackStatusChanged(mState); } unregisterAudioNoisyReceiver(); }
From source file:org.amahi.anywhere.tv.fragment.TvPlaybackAudioFragment.java
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public void playbackStateChanged() { if (mCurrentPlaybackState != PlaybackState.STATE_PLAYING) { mCurrentPlaybackState = PlaybackState.STATE_PLAYING; startProgressAutomation();/*from www . ja v a2s . co m*/ setFadingEnabled(false); mPlayPauseAction.setIndex(PlaybackControlsRow.PlayPauseAction.PAUSE); mPlayPauseAction.setIcon(mPlayPauseAction.getDrawable(PlaybackControlsRow.PlayPauseAction.PAUSE)); notifyChanged(mPlayPauseAction); } else { mCurrentPlaybackState = PlaybackState.STATE_PAUSED; stopProgressAutomation(); mPlayPauseAction.setIndex(PlaybackControlsRow.PlayPauseAction.PLAY); mPlayPauseAction.setIcon(mPlayPauseAction.getDrawable(PlaybackControlsRow.PlayPauseAction.PLAY)); notifyChanged(mPlayPauseAction); } }
From source file:com.sgottard.tvdemoapp.ui.PlaybackOverlayFragment.java
private void setupRows() { ClassPresenterSelector ps = new ClassPresenterSelector(); PlaybackControlsRowPresenter playbackControlsRowPresenter; if (SHOW_DETAIL) { playbackControlsRowPresenter = new PlaybackControlsRowPresenter(new DescriptionPresenter()); } else {//from ww w. j av a 2 s.co m playbackControlsRowPresenter = new PlaybackControlsRowPresenter(); } playbackControlsRowPresenter.setOnActionClickedListener(new OnActionClickedListener() { public void onActionClicked(Action action) { if (action.getId() == mPlayPauseAction.getId()) { togglePlayback(mPlayPauseAction.getIndex() == PlayPauseAction.PLAY); } else if (action.getId() == mSkipNextAction.getId()) { next(mCurrentPlaybackState == PlaybackState.STATE_PLAYING); } else if (action.getId() == mSkipPreviousAction.getId()) { prev(mCurrentPlaybackState == PlaybackState.STATE_PLAYING); } else if (action.getId() == mFastForwardAction.getId()) { fastForward(); } else if (action.getId() == mRewindAction.getId()) { fastRewind(); } if (action instanceof PlaybackControlsRow.MultiAction) { notifyChanged(action); } } }); playbackControlsRowPresenter.setSecondaryActionsHidden(HIDE_MORE_ACTIONS); ps.addClassPresenter(PlaybackControlsRow.class, playbackControlsRowPresenter); ps.addClassPresenter(ListRow.class, new ListRowPresenter()); mRowsAdapter = new ArrayObjectAdapter(ps); addPlaybackControlsRow(); addOtherRows(); setAdapter(mRowsAdapter); }
From source file:com.appdevper.mediaplayer.activity.FullScreenPlayerActivity.java
private void connectToSession(MediaSessionCompat.Token token) throws RemoteException { MediaControllerCompat mediaController = new MediaControllerCompat(FullScreenPlayerActivity.this, token); if (mediaController.getMetadata() == null) { finish();//from ww w. j a v a 2s . c o m return; } setSupportMediaController(mediaController); mediaController.registerCallback(mCallback); PlaybackStateCompat state = mediaController.getPlaybackState(); updatePlaybackState(state); MediaMetadataCompat metadata = mediaController.getMetadata(); if (metadata != null) { updateMediaDescription(metadata.getDescription()); updateDuration(metadata); } updateProgress(); if (state != null && (state.getState() == PlaybackState.STATE_PLAYING || state.getState() == PlaybackState.STATE_BUFFERING)) { scheduleSeekbarUpdate(); } }
From source file:com.example.android.supportv4.media.Playback.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 www . j ava 2 s. co m */ private void configMediaPlayerState() { Log.d(TAG, "configMediaPlayerState. mAudioFocus=" + mAudioFocus); if (mAudioFocus == AUDIO_NO_FOCUS_NO_DUCK) { // If we don't have audio focus and can't duck, we have to pause, if (mState == PlaybackState.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 && !mMediaPlayer.isPlaying()) { Log.d(TAG, "configMediaPlayerState startMediaPlayer. seeking to " + mCurrentPosition); if (mCurrentPosition == mMediaPlayer.getCurrentPosition()) { mMediaPlayer.start(); mState = PlaybackState.STATE_PLAYING; } else { mMediaPlayer.seekTo(mCurrentPosition); mState = PlaybackState.STATE_BUFFERING; } } mPlayOnFocusGain = false; } } if (mCallback != null) { mCallback.onPlaybackStatusChanged(mState); } }