Java Code Examples for android.support.v4.media.session.PlaybackStateCompat#STATE_CONNECTING
The following examples show how to use
android.support.v4.media.session.PlaybackStateCompat#STATE_CONNECTING .
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: PlaybackControlsFragment.java From LyricHere with Apache License 2.0 | 6 votes |
@Override public void onClick(View v) { PlaybackStateCompat stateObj = mMediaControllerProvider.getSupportMediaController().getPlaybackState(); final int state = stateObj == null ? PlaybackStateCompat.STATE_NONE : stateObj.getState(); LogUtils.d(TAG, "Button pressed, in state " + state); switch (v.getId()) { case R.id.play_pause: LogUtils.d(TAG, "Play button pressed, in state " + state); if (state == PlaybackStateCompat.STATE_PAUSED || state == PlaybackStateCompat.STATE_STOPPED || state == PlaybackStateCompat.STATE_NONE) { playMedia(); } else if (state == PlaybackStateCompat.STATE_PLAYING || state == PlaybackStateCompat.STATE_BUFFERING || state == PlaybackStateCompat.STATE_CONNECTING) { pauseMedia(); } break; } }
Example 2
Source File: PlayerView.java From Bop with Apache License 2.0 | 5 votes |
private void updatePlaybackState(PlaybackStateCompat state) { if (state == null) { return; } switch (state.getState()) { case PlaybackStateCompat.STATE_PLAYING: mFabView.setImageDrawable((ExtraUtils.getThemedIcon(getApplicationContext(), ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_pause)))); break; case PlaybackStateCompat.STATE_PAUSED: mFabView.setImageDrawable((ExtraUtils.getThemedIcon(getApplicationContext(), ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_play)))); break; case PlaybackStateCompat.STATE_NONE: break; case PlaybackStateCompat.STATE_STOPPED: finish(); break; default: case PlaybackStateCompat.STATE_BUFFERING: break; case PlaybackStateCompat.STATE_CONNECTING: break; case PlaybackStateCompat.STATE_ERROR: break; case PlaybackStateCompat.STATE_FAST_FORWARDING: break; case PlaybackStateCompat.STATE_REWINDING: break; case PlaybackStateCompat.STATE_SKIPPING_TO_NEXT: break; case PlaybackStateCompat.STATE_SKIPPING_TO_PREVIOUS: break; case PlaybackStateCompat.STATE_SKIPPING_TO_QUEUE_ITEM: break; } }
Example 3
Source File: PlaybackManager.java From YouTube-In-Background with MIT License | 5 votes |
/** * Switch to a different Playback instance, maintaining all playback state, if possible. * * @param playback switch to this playback */ public void switchToPlayback(Playback playback, boolean resumePlaying) { if (playback == null) { throw new IllegalArgumentException("Playback cannot be null"); } // Suspends current state. int oldState = this.playback.getState(); long pos = this.playback.getCurrentStreamPosition(); String currentMediaId = this.playback.getCurrentYouTubeVideoId(); this.playback.stop(false); playback.setCallback(this); playback.setCurrentYouTubeVideoId(currentMediaId); playback.seekTo(pos < 0 ? 0 : pos); playback.start(); // Swaps instance. this.playback = playback; switch (oldState) { case PlaybackStateCompat.STATE_BUFFERING: case PlaybackStateCompat.STATE_CONNECTING: case STATE_PAUSED: this.playback.pause(); break; case STATE_PLAYING: YouTubeVideo currentYouTubeVideo = queueManager.getCurrentVideo(); if (resumePlaying && currentYouTubeVideo != null) { LogHelper.e(TAG, "switchToPlayback: call | playback.play"); this.playback.play(currentYouTubeVideo); } else if (!resumePlaying) { this.playback.pause(); } else { this.playback.stop(true); } break; case PlaybackStateCompat.STATE_NONE: break; default: LogHelper.d(TAG, "Default called. Old state is ", oldState); } }
Example 4
Source File: MusicService.java From LyricHere with Apache License 2.0 | 5 votes |
/** * Helper to switch to a different Playback instance * * @param playback switch to this playback */ 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(); LogUtils.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: LogUtils.d(TAG, "Default called. Old state is ", oldState); } }
Example 5
Source File: MediaNotificationManager.java From YouTube-In-Background with MIT License | 4 votes |
/** * This may look strange, but the documentation for [Service.startForeground] * notes that "calling this method does *not* put the service in the started * state itself, even though the name sounds like it." * * @param state current playback state */ private void updateNotification(PlaybackStateCompat state) { int updatedState = state.getState(); // Skip building a notification when state is "none" and metadata is null. Notification notification = skipBuildNotification(updatedState) ? buildNotification(sessionToken) : null; if (notification != null && !hasRegisterReceiver) { mediaController.registerCallback(callback); IntentFilter filter = new IntentFilter(); filter.addAction(CUSTOM_ACTION_NEXT); filter.addAction(CUSTOM_ACTION_PAUSE); filter.addAction(CUSTOM_ACTION_PLAY); filter.addAction(CUSTOM_ACTION_PREV); filter.addAction(CUSTOM_ACTION_STOP); exoAudioService.registerReceiver(this, filter); hasRegisterReceiver = true; } switch (updatedState) { case STATE_BUFFERING: case STATE_PLAYING: if (notification != null) { notificationManager.notify(NOTIFICATION_ID, notification); } if (!isForegroundService) { Intent intent = new Intent(context, BackgroundExoAudioService.class); ContextCompat.startForegroundService(context, intent); exoAudioService.startForeground(NOTIFICATION_ID, notification); isForegroundService = true; } break; case PlaybackStateCompat.STATE_CONNECTING: case PlaybackStateCompat.STATE_ERROR: case PlaybackStateCompat.STATE_FAST_FORWARDING: case PlaybackStateCompat.STATE_NONE: case PlaybackStateCompat.STATE_PAUSED: 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_STOPPED: if (isForegroundService) { exoAudioService.stopForeground(false); isForegroundService = false; // If playback has ended, also stop the service. if (updatedState == PlaybackStateCompat.STATE_NONE) { exoAudioService.stopSelf(); } if (notification != null) { notificationManager.notify(NOTIFICATION_ID, notification); } else { removeNowPlayingNotification(); } } break; } }