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:com.torrenttunes.android.MusicService.java
/** * Helper to switch to a different Playback instance * @param playback switch to this playback *//*from w w w .j a v a2s . co m*/ private void switchToPlayer(Playback playback, boolean resumePlaying) { if (playback == null) { throw new IllegalArgumentException("Playback cannot be null"); } // suspend the current one. int oldState = mPlayback.getState(); int pos = mPlayback.getCurrentStreamPosition(); String currentMediaId = mPlayback.getCurrentMediaId(); LogHelper.d(TAG, "Current position from " + playback + " is ", pos); mPlayback.stop(false); playback.setCallback(this); playback.setCurrentStreamPosition(pos < 0 ? 0 : pos); playback.setCurrentMediaId(currentMediaId); 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 && QueueHelper.isIndexPlayable(mCurrentIndexOnQueue, mPlayingQueue)) { mPlayback.play(mPlayingQueue.get(mCurrentIndexOnQueue)); } else if (!resumePlaying) { mPlayback.pause(); } else { mPlayback.stop(true); } break; case PlaybackStateCompat.STATE_NONE: break; default: LogHelper.d(TAG, "Default called. Old state is ", oldState); } }
From source file:android.support.v7.app.MediaRouteControllerDialog.java
private void updatePlaybackControlLayout() { if (canShowPlaybackControlLayout()) { CharSequence title = mDescription == null ? null : mDescription.getTitle(); boolean hasTitle = !TextUtils.isEmpty(title); CharSequence subtitle = mDescription == null ? null : mDescription.getSubtitle(); boolean hasSubtitle = !TextUtils.isEmpty(subtitle); boolean showTitle = false; boolean showSubtitle = false; if (mRoute.getPresentationDisplayId() != MediaRouter.RouteInfo.PRESENTATION_DISPLAY_ID_NONE) { // The user is currently casting screen. mTitleView.setText(R.string.mr_controller_casting_screen); showTitle = true;//from w w w . jav a 2s. c om } else if (mState == null || mState.getState() == PlaybackStateCompat.STATE_NONE) { // Show "No media selected" as we don't yet know the playback state. mTitleView.setText(R.string.mr_controller_no_media_selected); showTitle = true; } else if (!hasTitle && !hasSubtitle) { mTitleView.setText(R.string.mr_controller_no_info_available); showTitle = true; } else { if (hasTitle) { mTitleView.setText(title); showTitle = true; } if (hasSubtitle) { mSubtitleView.setText(subtitle); showSubtitle = true; } } mTitleView.setVisibility(showTitle ? View.VISIBLE : View.GONE); mSubtitleView.setVisibility(showSubtitle ? View.VISIBLE : View.GONE); if (mState != null) { boolean isPlaying = mState.getState() == PlaybackStateCompat.STATE_BUFFERING || mState.getState() == PlaybackStateCompat.STATE_PLAYING; boolean supportsPlay = (mState.getActions() & (PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PLAY_PAUSE)) != 0; boolean supportsPause = (mState.getActions() & (PlaybackStateCompat.ACTION_PAUSE | PlaybackStateCompat.ACTION_PLAY_PAUSE)) != 0; if (isPlaying && supportsPause) { mPlayPauseButton.setVisibility(View.VISIBLE); mPlayPauseButton.setImageResource( MediaRouterThemeHelper.getThemeResource(mContext, R.attr.mediaRoutePauseDrawable)); mPlayPauseButton .setContentDescription(mContext.getResources().getText(R.string.mr_controller_pause)); } else if (!isPlaying && supportsPlay) { mPlayPauseButton.setVisibility(View.VISIBLE); mPlayPauseButton.setImageResource( MediaRouterThemeHelper.getThemeResource(mContext, R.attr.mediaRoutePlayDrawable)); mPlayPauseButton .setContentDescription(mContext.getResources().getText(R.string.mr_controller_play)); } else { mPlayPauseButton.setVisibility(View.GONE); } } } }
From source file:androidx.mediarouter.app.MediaRouteControllerDialog.java
private void updatePlaybackControlLayout() { if (canShowPlaybackControlLayout()) { CharSequence title = mDescription == null ? null : mDescription.getTitle(); boolean hasTitle = !TextUtils.isEmpty(title); CharSequence subtitle = mDescription == null ? null : mDescription.getSubtitle(); boolean hasSubtitle = !TextUtils.isEmpty(subtitle); boolean showTitle = false; boolean showSubtitle = false; if (mRoute.getPresentationDisplayId() != MediaRouter.RouteInfo.PRESENTATION_DISPLAY_ID_NONE) { // The user is currently casting screen. mTitleView.setText(R.string.mr_controller_casting_screen); showTitle = true;//from ww w . j a va 2 s . c o m } else if (mState == null || mState.getState() == PlaybackStateCompat.STATE_NONE) { // Show "No media selected" as we don't yet know the playback state. mTitleView.setText(R.string.mr_controller_no_media_selected); showTitle = true; } else if (!hasTitle && !hasSubtitle) { mTitleView.setText(R.string.mr_controller_no_info_available); showTitle = true; } else { if (hasTitle) { mTitleView.setText(title); showTitle = true; } if (hasSubtitle) { mSubtitleView.setText(subtitle); showSubtitle = true; } } mTitleView.setVisibility(showTitle ? View.VISIBLE : View.GONE); mSubtitleView.setVisibility(showSubtitle ? View.VISIBLE : View.GONE); if (mState != null) { boolean isPlaying = mState.getState() == PlaybackStateCompat.STATE_BUFFERING || mState.getState() == PlaybackStateCompat.STATE_PLAYING; Context playbackControlButtonContext = mPlaybackControlButton.getContext(); boolean visible = true; int iconDrawableAttr = 0; int iconDescResId = 0; if (isPlaying && isPauseActionSupported()) { iconDrawableAttr = R.attr.mediaRoutePauseDrawable; iconDescResId = R.string.mr_controller_pause; } else if (isPlaying && isStopActionSupported()) { iconDrawableAttr = R.attr.mediaRouteStopDrawable; iconDescResId = R.string.mr_controller_stop; } else if (!isPlaying && isPlayActionSupported()) { iconDrawableAttr = R.attr.mediaRoutePlayDrawable; iconDescResId = R.string.mr_controller_play; } else { visible = false; } mPlaybackControlButton.setVisibility(visible ? View.VISIBLE : View.GONE); if (visible) { mPlaybackControlButton.setImageResource(MediaRouterThemeHelper .getThemeResource(playbackControlButtonContext, iconDrawableAttr)); mPlaybackControlButton.setContentDescription( playbackControlButtonContext.getResources().getText(iconDescResId)); } } } }
From source file:androidx.media.widget.VideoView2.java
private int getCorrespondingPlaybackState() { switch (mCurrentState) { case STATE_ERROR: return PlaybackStateCompat.STATE_ERROR; case STATE_IDLE: return PlaybackStateCompat.STATE_NONE; case STATE_PREPARING: return PlaybackStateCompat.STATE_CONNECTING; case STATE_PREPARED: return PlaybackStateCompat.STATE_PAUSED; case STATE_PLAYING: return PlaybackStateCompat.STATE_PLAYING; case STATE_PAUSED: return PlaybackStateCompat.STATE_PAUSED; case STATE_PLAYBACK_COMPLETED: return PlaybackStateCompat.STATE_STOPPED; default:/*from www.jav a2s . c o m*/ return -1; } }