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:nuclei.media.playback.PlaybackManager.java
/** * Update the current media player state, optionally showing an error message. * * @param error if not null, error message to present to the user. *//*w w w . j a v a 2 s .c o m*/ public void updatePlaybackState(Exception error, boolean canPause) { long position = PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN; if (mPlayback != null && mPlayback.isConnected()) { position = mPlayback.getCurrentStreamPosition(); } //noinspection ResourceType final PlaybackStateCompat.Builder stateBuilder = new PlaybackStateCompat.Builder() .setActions(getAvailableActions()); int state = mPlayback == null ? PlaybackStateCompat.STATE_NONE : mPlayback.getState(); // If there is an error message, send it to the playback state: if (error != null) { mHandler.removeMessages(TIMER_COUNTDOWN); mHandler.removeMessages(TIMER_TIMING); int errorCode = ResourceProvider.getInstance().getExceptionCode(error); String message = ResourceProvider.getInstance().getExceptionMessage(error); if (message == null) message = error.getMessage(); // Error states are really only supposed to be used for errors that cause playback to // stop unexpectedly and persist until the user takes action to fix it. stateBuilder.setErrorMessage(errorCode, message); state = PlaybackStateCompat.STATE_ERROR; if (mPlayback != null) { int lastState = state; mPlayback.setState(state); if (mPlayback.isPlaying()) { mPlayback.setState(lastState); state = lastState; } else if (canPause) { mPlayback.pause(); } } MediaProvider.getInstance().onError(error); } float audioSpeed; if (mPlayback instanceof CastPlayback) audioSpeed = 1; else audioSpeed = mServiceCallback.getAudioSpeed(); //noinspection ResourceType stateBuilder.setState(state, position, audioSpeed, SystemClock.elapsedRealtime()); mServiceCallback.onPlaybackStateUpdated(stateBuilder.build()); if (state == PlaybackStateCompat.STATE_PLAYING) { if (mTimer > -1 && !mHandler.hasMessages(TIMER_COUNTDOWN)) mHandler.sendEmptyMessageDelayed(TIMER_COUNTDOWN, ONE_SECOND); if (mPlayback.getTiming() != null && !mHandler.hasMessages(TIMER_TIMING)) mHandler.sendEmptyMessageDelayed(TIMER_TIMING, ONE_SECOND); } if (state == PlaybackStateCompat.STATE_PLAYING) { mServiceCallback.onNotificationRequired(); } }
From source file:com.example.android.supportv4.media.QueueFragment.java
private void onPlaybackStateChanged(PlaybackStateCompat state) { Log.d(TAG, "onPlaybackStateChanged " + state); if (state == null) { return;/*from w ww. j a v a 2s. c om*/ } mQueueAdapter.setActiveQueueItemId(state.getActiveQueueItemId()); mQueueAdapter.notifyDataSetChanged(); boolean enablePlay = false; StringBuilder statusBuilder = new StringBuilder(); switch (state.getState()) { case PlaybackStateCompat.STATE_PLAYING: statusBuilder.append("playing"); enablePlay = false; break; case PlaybackStateCompat.STATE_PAUSED: statusBuilder.append("paused"); enablePlay = true; break; case PlaybackStateCompat.STATE_STOPPED: statusBuilder.append("ended"); enablePlay = true; break; case PlaybackStateCompat.STATE_ERROR: statusBuilder.append("error: ").append(state.getErrorMessage()); break; case PlaybackStateCompat.STATE_BUFFERING: statusBuilder.append("buffering"); break; case PlaybackStateCompat.STATE_NONE: statusBuilder.append("none"); enablePlay = false; break; case PlaybackStateCompat.STATE_CONNECTING: statusBuilder.append("connecting"); break; default: statusBuilder.append(mPlaybackState); } statusBuilder.append(" -- At position: ").append(state.getPosition()); Log.d(TAG, statusBuilder.toString()); if (enablePlay) { mPlayPause.setImageDrawable( getActivity().getResources().getDrawable(R.drawable.ic_play_arrow_white_24dp)); } else { mPlayPause.setImageDrawable(getActivity().getResources().getDrawable(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); Log.d(TAG, "Queue From MediaController *** Title " + mMediaController.getQueueTitle() + "\n: Queue: " + mMediaController.getQueue() + "\n Metadata " + mMediaController.getMetadata()); }
From source file:com.classiqo.nativeandroid_32bitz.playback.PlaybackManager.java
public void switchToPlayback(Playback playback, boolean resumePlaying) { if (playback == null) { throw new IllegalArgumentException("Playback cannot be null"); }//from w ww . ja v a 2 s . co m int oldState = mPlayback.getState(); int pos = mPlayback.getCurrentStreamPosition(); String currentMediaId = mPlayback.getCurrentMediaId(); mPlayback.stop(false); playback.setCallback(this); playback.setCurrentStreamPosition(pos < 0 ? 0 : pos); playback.setCurrentMediaId(currentMediaId); playback.start(); mPlayback = playback; switch (oldState) { case PlaybackStateCompat.STATE_BUFFERING: case PlaybackStateCompat.STATE_CONNECTING: case PlaybackStateCompat.STATE_PAUSED: mPlayback.pause(); break; case PlaybackStateCompat.STATE_PLAYING: MediaSessionCompat.QueueItem currentMusic = mQueueManager.getCurrentMusic(); if (resumePlaying && currentMusic != null) { mPlayback.play(currentMusic); } 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:org.runbuddy.tomahawk.views.PlaybackPanel.java
public void setup(final boolean isPanelExpanded) { mInitialized = true;//w w w .j a v a2s.c om mPlayPauseButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mMediaController != null) { int playState = mMediaController.getPlaybackState().getState(); if (playState == PlaybackStateCompat.STATE_PAUSED || playState == PlaybackStateCompat.STATE_NONE) { mMediaController.getTransportControls().play(); } else if (playState == PlaybackStateCompat.STATE_PLAYING) { mMediaController.getTransportControls().pause(); mMediaController.getTransportControls() .sendCustomAction(PlaybackService.ACTION_STOP_NOTIFICATION, null); } } } }); mPlayPauseButton.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { PreferenceUtils.edit().putBoolean(PreferenceUtils.COACHMARK_SEEK_DISABLED, true).apply(); View coachMark = ViewUtils.ensureInflation(PlaybackPanel.this, R.id.playbackpanel_seek_coachmark_stub, R.id.playbackpanel_seek_coachmark); coachMark.setVisibility(GONE); if (!isPanelExpanded || getResources().getBoolean(R.bool.is_landscape)) { AnimationUtils.fade(mTextViewContainer, AnimationUtils.DURATION_PLAYBACKSEEKMODE, false, true); } AnimationUtils.fade(mPlayPauseButtonContainer, AnimationUtils.DURATION_PLAYBACKSEEKMODE, false, true); AnimationUtils.fade(mResolverImageView, AnimationUtils.DURATION_PLAYBACKSEEKMODE, false, true); AnimationUtils.fade(mCompletionTimeTextView, AnimationUtils.DURATION_PLAYBACKSEEKMODE, false, true); AnimationUtils.fade(mProgressBarThumb, AnimationUtils.DURATION_PLAYBACKSEEKMODE, true, true); AnimationUtils.fade(mCurrentTimeTextView, AnimationUtils.DURATION_PLAYBACKSEEKMODE, true, true); AnimationUtils.fade(mSeekTimeTextView, AnimationUtils.DURATION_PLAYBACKSEEKMODE, true, true); AnimationUtils.fade(mProgressBar, AnimationUtils.DURATION_PLAYBACKSEEKMODE, true, true); mPlayPauseButton.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP) { if (!isPanelExpanded || getResources().getBoolean(R.bool.is_landscape)) { AnimationUtils.fade(mTextViewContainer, AnimationUtils.DURATION_PLAYBACKSEEKMODE, true, true); } AnimationUtils.fade(mPlayPauseButtonContainer, AnimationUtils.DURATION_PLAYBACKSEEKMODE, true, true); AnimationUtils.fade(mResolverImageView, AnimationUtils.DURATION_PLAYBACKSEEKMODE, true, true); AnimationUtils.fade(mCompletionTimeTextView, AnimationUtils.DURATION_PLAYBACKSEEKMODE, true, true); AnimationUtils.fade(mProgressBarThumb, AnimationUtils.DURATION_PLAYBACKSEEKMODE, false, true); AnimationUtils.fade(mCurrentTimeTextView, AnimationUtils.DURATION_PLAYBACKSEEKMODE, false, true); AnimationUtils.fade(mSeekTimeTextView, AnimationUtils.DURATION_PLAYBACKSEEKMODE, false, true); AnimationUtils.fade(mProgressBar, AnimationUtils.DURATION_PLAYBACKSEEKMODE, false, true); mPlayPauseButton.setOnTouchListener(null); if (!mAbortSeeking) { int seekTime = (int) ((mLastThumbPosition - mProgressBar.getX()) / mProgressBar.getWidth() * mCurrentDuration); mMediaController.getTransportControls().seekTo(seekTime); } } else if (event.getAction() == MotionEvent.ACTION_MOVE) { float eventX = event.getX(); float progressBarX = mProgressBar.getX(); float finalX; if (eventX > mProgressBar.getWidth() + progressBarX) { // Only fade out thumb if eventX is above the threshold int threshold = getResources() .getDimensionPixelSize(R.dimen.playback_panel_seekbar_threshold_end); mAbortSeeking = eventX > mProgressBar.getWidth() + progressBarX + threshold; finalX = mProgressBar.getWidth() + progressBarX; } else if (eventX < progressBarX) { // Only fade out thumb if eventX is below the threshold int threshold = getResources() .getDimensionPixelSize(R.dimen.playback_panel_seekbar_threshold_start); mAbortSeeking = eventX < progressBarX - threshold; finalX = progressBarX; } else { mAbortSeeking = false; finalX = eventX; } if (mAbortSeeking) { AnimationUtils.fade(mProgressBarThumb, AnimationUtils.DURATION_PLAYBACKSEEKMODE_ABORT, false, true); } else { AnimationUtils.fade(mProgressBarThumb, AnimationUtils.DURATION_PLAYBACKSEEKMODE_ABORT, true, true); } mLastThumbPosition = finalX; mProgressBarThumb.setX(finalX); int seekTime = (int) ((finalX - mProgressBar.getX()) / mProgressBar.getWidth() * mCurrentDuration); mSeekTimeTextView.setText(ViewUtils.durationToString(seekTime)); } return false; } }); return true; } }); setupAnimations(); }
From source file:net.simno.klingar.ui.BrowserController.java
private void observePlayback() { disposables.add(musicController.state().compose(bindUntilEvent(DETACH)).compose(rx.flowableSchedulers()) .subscribe(state -> {/* w w w. j a v a 2 s.c om*/ switch (state) { case PlaybackStateCompat.STATE_ERROR: case PlaybackStateCompat.STATE_NONE: case PlaybackStateCompat.STATE_STOPPED: for (Router router : getChildRouters()) { removeChildRouter(router); } break; default: Router miniplayerRouter = getChildRouter(miniplayerContainer); if (!miniplayerRouter.hasRootController()) { miniplayerRouter.setRoot(RouterTransaction.with(new MiniPlayerController(null))); } } }, Rx::onError)); }
From source file:com.appdevper.mediaplayer.app.PlaybackManager.java
/** * Switch to a different Playback instance, maintaining all playback state, if possible. * * @param playback switch to this playback */// w w w . j ava 2 s .c om public void switchToPlayback(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(); 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: MediaSessionCompat.QueueItem currentMusic = mQueueManager.getCurrentMusic(); if (resumePlaying && currentMusic != null) { mPlayback.play(currentMusic); } 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:com.scooter1556.sms.android.fragment.tv.TvVideoPlayerFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); surfaceHolder = ((TvVideoPlaybackActivity) getActivity()).getSurfaceHolder(); surfaceHolder.addCallback(this); subtitleView = (SubtitleView) getActivity().findViewById(R.id.subtitle_view); if (subtitleView != null) { subtitleView.setUserDefaultStyle(); subtitleView.setUserDefaultTextSize(); }/*from w w w .j av a 2s. c o m*/ handler = new Handler(); seekHandler = new Handler(); Bundle bundle = getActivity().getIntent().getExtras(); if (bundle != null) { currentMedia = getActivity().getIntent().getParcelableExtra(EXTRA_QUEUE_ITEM); } this.playbackState = PlaybackStateCompat.STATE_NONE; // Set playback instance in our playback manager playbackManager = PlaybackManager.getInstance(); playbackManager.setPlayback(this); // Set playback manager callback this.setCallback(playbackManager); setBackgroundType(BACKGROUND_TYPE); setFadingEnabled(false); setupRows(); // Get session ID RESTService.getInstance().createSession(new TextHttpResponseHandler() { @Override public void onFailure(int statusCode, cz.msebera.android.httpclient.Header[] headers, String response, Throwable throwable) { Log.e(TAG, "Failed to initialise session"); } @Override public void onSuccess(int statusCode, cz.msebera.android.httpclient.Header[] headers, String response) { // Parse result sessionId = UUID.fromString(response); Log.d(TAG, "New session ID: " + sessionId); // Start Playback play(currentMedia); } }); }
From source file:com.murati.oszk.audiobook.playback.PlaybackManager.java
/** * Switch to a different Playback instance, maintaining all playback state, if possible. * * @param playback switch to this playback *//*from w ww . j a v a 2 s. c om*/ public void switchToPlayback(Playback playback, boolean resumePlaying) { if (playback == null) { throw new IllegalArgumentException("Playback cannot be null"); } // Suspends current state. int oldState = mPlayback.getState(); long pos = mPlayback.getCurrentStreamPosition(); String currentMediaId = mPlayback.getCurrentMediaId(); mPlayback.stop(false); playback.setCallback(this); playback.setCurrentMediaId(currentMediaId); playback.seekTo(pos < 0 ? 0 : pos); playback.start(); // Swaps instance. mPlayback = playback; switch (oldState) { case PlaybackStateCompat.STATE_BUFFERING: case PlaybackStateCompat.STATE_CONNECTING: case PlaybackStateCompat.STATE_PAUSED: mPlayback.pause(); break; case PlaybackStateCompat.STATE_PLAYING: MediaSessionCompat.QueueItem currentMusic = mQueueManager.getCurrentTrack(); if (resumePlaying && currentMusic != null) { mPlayback.play(currentMusic); } 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:com.torrenttunes.android.MusicService.java
@Override public void onCreate() { super.onCreate(); LogHelper.d(TAG, "onCreate"); mPlayingQueue = new ArrayList<>(); mMusicProvider = new MusicProvider(); mPackageValidator = new PackageValidator(this); mEventReceiver = new ComponentName(getPackageName(), MediaButtonReceiver.class.getName()); Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); mediaButtonIntent.setComponent(mEventReceiver); mMediaPendingIntent = PendingIntent.getBroadcast(this, 0, mediaButtonIntent, 0); // Start a new MediaSession mSession = new MediaSessionCompat(this, "MusicService", mEventReceiver, mMediaPendingIntent); final MediaSessionCallback cb = new MediaSessionCallback(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // Shouldn't really have to do this but the MediaSessionCompat method uses // an internal proxy class, which doesn't forward events such as // onPlayFromMediaId when running on Lollipop. final MediaSession session = (MediaSession) mSession.getMediaSession(); // session.setCallback(new MediaSessionCallbackProxy(cb)); } else {/* ww w. j a v a 2s .c o m*/ mSession.setCallback(cb); } setSessionToken(mSession.getSessionToken()); mSession.setFlags( MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS); mPlayback = new LocalPlayback(this, mMusicProvider); mPlayback.setState(PlaybackStateCompat.STATE_NONE); mPlayback.setCallback(this); mPlayback.start(); Context context = getApplicationContext(); Intent intent = new Intent(context, NowPlayingActivity.class); PendingIntent pi = PendingIntent.getActivity(context, 99 /*request code*/, intent, PendingIntent.FLAG_UPDATE_CURRENT); mSession.setSessionActivity(pi); mSessionExtras = new Bundle(); CarHelper.setSlotReservationFlags(mSessionExtras, true, true, true); mSession.setExtras(mSessionExtras); updatePlaybackState(null); mMediaNotificationManager = new MediaNotificationManager(this); mCastManager = VideoCastManager.getInstance(); mCastManager.addVideoCastConsumer(mCastConsumer); mMediaRouter = MediaRouter.getInstance(getApplicationContext()); }
From source file:com.example.android.AudioArchive.ui.FullScreenPlayerActivity.java
private void updatePlaybackState(PlaybackStateCompat state) { if (state == null) { return;/*from w w w.j av a 2 s . c o m*/ } 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); break; case PlaybackStateCompat.STATE_PAUSED: mControllers.setVisibility(VISIBLE); mLoading.setVisibility(INVISIBLE); mPlayPause.setVisibility(VISIBLE); mPlayPause.setImageDrawable(mPlayDrawable); break; case PlaybackStateCompat.STATE_NONE: case PlaybackStateCompat.STATE_STOPPED: mLoading.setVisibility(INVISIBLE); mPlayPause.setVisibility(VISIBLE); mPlayPause.setImageDrawable(mPlayDrawable); break; case PlaybackStateCompat.STATE_BUFFERING: mPlayPause.setVisibility(INVISIBLE); mLoading.setVisibility(VISIBLE); mLine3.setText(R.string.loading); 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); }