Java Code Examples for android.support.v4.media.session.PlaybackStateCompat#STATE_NONE
The following examples show how to use
android.support.v4.media.session.PlaybackStateCompat#STATE_NONE .
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: LocalPlayback.java From klingar with Apache License 2.0 | 6 votes |
@Override @State public int getState() { if (exoPlayer == null) { return exoPlayerNullIsStopped ? PlaybackStateCompat.STATE_STOPPED : PlaybackStateCompat.STATE_NONE; } switch (exoPlayer.getPlaybackState()) { case Player.STATE_IDLE: case Player.STATE_ENDED: return PlaybackStateCompat.STATE_PAUSED; case Player.STATE_BUFFERING: return PlaybackStateCompat.STATE_BUFFERING; case Player.STATE_READY: return exoPlayer.getPlayWhenReady() ? PlaybackStateCompat.STATE_PLAYING : PlaybackStateCompat.STATE_PAUSED; default: return PlaybackStateCompat.STATE_NONE; } }
Example 2
Source File: MediaControlsHelper.java From AcDisplay with GNU General Public License v2.0 | 6 votes |
@Override public void onPlaybackStateChanged(int state) { Check.getInstance().isInMainThread(); switch (state) { case PlaybackStateCompat.STATE_PLAYING: mHandler.removeMessages(H.MSG_HIDE_MEDIA_WIDGET); if (!mShowing) { mShowing = true; notifyOnStateChanged(); } break; default: if (mShowing) { int delay = state == PlaybackStateCompat.STATE_NONE ? 500 : DELAY; mHandler.sendEmptyMessageDelayed(H.MSG_HIDE_MEDIA_WIDGET, delay); } break; } }
Example 3
Source File: AdapterMusic.java From DMAudioStreamer with Apache License 2.0 | 6 votes |
private Drawable getDrawableByState(Context context, int state) { switch (state) { case PlaybackStateCompat.STATE_NONE: Drawable pauseDrawable = ContextCompat.getDrawable(context, R.drawable.ic_play); DrawableCompat.setTintList(pauseDrawable, colorPlay); return pauseDrawable; case PlaybackStateCompat.STATE_PLAYING: AnimationDrawable animation = (AnimationDrawable) ContextCompat.getDrawable(context, R.drawable.equalizer); DrawableCompat.setTintList(animation, colorPlay); animation.start(); return animation; case PlaybackStateCompat.STATE_PAUSED: Drawable playDrawable = ContextCompat.getDrawable(context, R.drawable.equalizer); DrawableCompat.setTintList(playDrawable, colorPause); return playDrawable; default: Drawable noneDrawable = ContextCompat.getDrawable(context, R.drawable.ic_play); DrawableCompat.setTintList(noneDrawable, colorPlay); return noneDrawable; } }
Example 4
Source File: TrackFragment.java From Melophile with Apache License 2.0 | 6 votes |
@OnClick(R.id.play_pause) public void playPause() { lastState = null; MediaControllerCompat controllerCompat = MediaControllerCompat.getMediaController(getActivity()); PlaybackStateCompat stateCompat = controllerCompat.getPlaybackState(); if (stateCompat != null) { MediaControllerCompat.TransportControls controls = controllerCompat.getTransportControls(); switch (stateCompat.getState()) { case PlaybackStateCompat.STATE_PLAYING: case PlaybackStateCompat.STATE_BUFFERING: controls.pause(); break; case PlaybackStateCompat.STATE_NONE: case PlaybackStateCompat.STATE_PAUSED: case PlaybackStateCompat.STATE_STOPPED: controls.play(); break; default: Log.d(TAG, "State " + stateCompat.getState()); } } }
Example 5
Source File: MediaNotificationManager.java From react-native-streaming-audio-player with MIT License | 5 votes |
@Override public void onPlaybackStateChanged(@NonNull PlaybackStateCompat state) { mPlaybackState = state; if (state.getState() == PlaybackStateCompat.STATE_STOPPED || state.getState() == PlaybackStateCompat.STATE_NONE) { stopNotification(); } else { Notification notification = createNotification(); if (notification != null) { mNotificationManager.notify(NOTIFICATION_ID, notification); } } }
Example 6
Source File: MediaNotificationManager.java From LyricHere with Apache License 2.0 | 5 votes |
@Override public void onPlaybackStateChanged(PlaybackStateCompat state) { mPlaybackState = state; LogUtils.d(TAG, "Received new playback state", state); if (state != null && (state.getState() == PlaybackStateCompat.STATE_STOPPED || state.getState() == PlaybackStateCompat.STATE_NONE)) { stopNotification(); } else { Notification notification = createNotification(); if (notification != null) { mNotificationManager.notify(NOTIFICATION_ID, notification); } } }
Example 7
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 8
Source File: TrackNotification.java From Melophile with Apache License 2.0 | 5 votes |
public void updatePlaybackState(PlaybackStateCompat playbackState) { this.playbackState = playbackState; if (playbackState.getState() == PlaybackStateCompat.STATE_STOPPED || playbackState.getState() == PlaybackStateCompat.STATE_NONE) { stopNotification(); } else { updateNotification(); } }
Example 9
Source File: MediaSessionManager.java From react-native-jw-media-player with MIT License | 5 votes |
private void updatePlaybackState(PlayerState playerState) { PlaybackStateCompat.Builder newPlaybackState = getPlaybackStateBuilder(); long capabilities = getCapabilities(playerState); //noinspection WrongConstant newPlaybackState.setActions(capabilities); int playbackStateCompat = PlaybackStateCompat.STATE_NONE; switch (playerState) { case PLAYING: playbackStateCompat = PlaybackStateCompat.STATE_PLAYING; break; case PAUSED: playbackStateCompat = PlaybackStateCompat.STATE_PAUSED; break; case BUFFERING: playbackStateCompat = PlaybackStateCompat.STATE_BUFFERING; break; case IDLE: if (mReceivedError) { playbackStateCompat = PlaybackStateCompat.STATE_ERROR; } else { playbackStateCompat = PlaybackStateCompat.STATE_STOPPED; } break; } if (mPlayer != null) { newPlaybackState.setState(playbackStateCompat, (long)mPlayer.getPosition(), mPlayer.getPlaybackRate()); // PLAYBACK_RATE mMediaSessionCompat.setPlaybackState(newPlaybackState.build()); mNotificationWrapper .createNotification(mPlayer.getContext(), mMediaSessionCompat, capabilities); } }
Example 10
Source File: Playback.java From react-native-streaming-audio-player with MIT License | 5 votes |
public Playback(Context context) { this.mContext = context; this.mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); // Create the Wifi lock (this does not acquire the lock, this just creates it) this.mWifiLock = ((WifiManager) context.getSystemService(Context.WIFI_SERVICE)) .createWifiLock(WifiManager.WIFI_MODE_FULL, "playback_lock"); this.mState = PlaybackStateCompat.STATE_NONE; }
Example 11
Source File: MediaNotificationManager.java From react-native-audio-streaming-player with MIT License | 5 votes |
@Override public void onPlaybackStateChanged(@NonNull PlaybackStateCompat state) { mPlaybackState = state; if (state.getState() == PlaybackStateCompat.STATE_STOPPED || state.getState() == PlaybackStateCompat.STATE_NONE) { stopNotification(); } else { Notification notification = createNotification(); if (notification != null) { mNotificationManager.notify(NOTIFICATION_ID, notification); } } }
Example 12
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 13
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 14
Source File: AudioPlaybackListener.java From DMAudioStreamer with Apache License 2.0 | 4 votes |
public AudioPlaybackListener(Context context) { this.mContext = context; this.mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); this.mWifiLock = ((WifiManager) context.getSystemService(Context.WIFI_SERVICE)).createWifiLock(WifiManager.WIFI_MODE_FULL, "dmAudioStreaming_Lock"); this.mState = PlaybackStateCompat.STATE_NONE; }
Example 15
Source File: MusicActivity.java From DMAudioStreamer with Apache License 2.0 | 4 votes |
@Override public void updatePlaybackState(int state) { Logger.e("updatePlaybackState: ", "" + state); switch (state) { case PlaybackStateCompat.STATE_PLAYING: pgPlayPauseLayout.setVisibility(View.INVISIBLE); btn_play.Play(); if (currentSong != null) { currentSong.setPlayState(PlaybackStateCompat.STATE_PLAYING); notifyAdapter(currentSong); } break; case PlaybackStateCompat.STATE_PAUSED: pgPlayPauseLayout.setVisibility(View.INVISIBLE); btn_play.Pause(); if (currentSong != null) { currentSong.setPlayState(PlaybackStateCompat.STATE_PAUSED); notifyAdapter(currentSong); } break; case PlaybackStateCompat.STATE_NONE: currentSong.setPlayState(PlaybackStateCompat.STATE_NONE); notifyAdapter(currentSong); break; case PlaybackStateCompat.STATE_STOPPED: pgPlayPauseLayout.setVisibility(View.INVISIBLE); btn_play.Pause(); audioPg.setValue(0); if (currentSong != null) { currentSong.setPlayState(PlaybackStateCompat.STATE_NONE); notifyAdapter(currentSong); } break; case PlaybackStateCompat.STATE_BUFFERING: pgPlayPauseLayout.setVisibility(View.VISIBLE); if (currentSong != null) { currentSong.setPlayState(PlaybackStateCompat.STATE_NONE); notifyAdapter(currentSong); } break; } }
Example 16
Source File: TrackFragment.java From Melophile with Apache License 2.0 | 4 votes |
public void updatePlaybackState(PlaybackStateCompat stateCompat) { if (stateCompat == null) return; lastState = stateCompat; updateRepeatMode(isActionApplied(stateCompat.getActions(), PlaybackStateCompat.ACTION_SET_REPEAT_MODE)); updateShuffleMode(isActionApplied(stateCompat.getActions(), PlaybackStateCompat.ACTION_SET_SHUFFLE_MODE_ENABLED)); //check the state switch (stateCompat.getState()) { case PlaybackStateCompat.STATE_PLAYING: playPause.setVisibility(VISIBLE); if (playPause.isPlay()) { playPause.change(false, true); } startSeekBarUpdate(); break; case PlaybackStateCompat.STATE_PAUSED: // mControllers.setVisibility(VISIBLE); // mLoading.setVisibility(INVISIBLE); playPause.setVisibility(VISIBLE); if (!playPause.isPlay()) { playPause.change(true, true); } stopSeekBarUpdate(); break; case PlaybackStateCompat.STATE_NONE: case PlaybackStateCompat.STATE_STOPPED: playPause.setVisibility(VISIBLE); if (playPause.isPlay()) { playPause.change(false, true); } stopSeekBarUpdate(); break; case PlaybackStateCompat.STATE_BUFFERING: playPause.setVisibility(INVISIBLE); stopSeekBarUpdate(); break; default: Log.d(TAG, "Unhandled state " + stateCompat.getState()); } }
Example 17
Source File: RemoteControlClientLP.java From Popeens-DSub with GNU General Public License v3.0 | 4 votes |
@Override public void setPlaybackState(int state, int index, int queueSize) { PlaybackStateCompat.Builder builder = new PlaybackStateCompat.Builder(); int newState = PlaybackStateCompat.STATE_NONE; switch(state) { case RemoteControlClient.PLAYSTATE_PLAYING: newState = PlaybackStateCompat.STATE_PLAYING; break; case RemoteControlClient.PLAYSTATE_STOPPED: newState = PlaybackStateCompat.STATE_STOPPED; break; case RemoteControlClient.PLAYSTATE_PAUSED: newState = PlaybackStateCompat.STATE_PAUSED; break; case RemoteControlClient.PLAYSTATE_BUFFERING: newState = PlaybackStateCompat.STATE_BUFFERING; break; } long position = -1; if(state == RemoteControlClient.PLAYSTATE_PLAYING || state == RemoteControlClient.PLAYSTATE_PAUSED) { position = downloadService.getPlayerPosition(); } builder.setState(newState, position, 1.0f); DownloadFile downloadFile = downloadService.getCurrentPlaying(); Entry entry = null; boolean isSong = true; if(downloadFile != null) { entry = downloadFile.getSong(); isSong = entry.isSong(); } builder.setActions(getPlaybackActions(isSong, index, queueSize)); if(entry != null) { addCustomActions(entry, builder); builder.setActiveQueueItemId(entry.getId().hashCode()); } PlaybackStateCompat playbackState = builder.build(); mediaSession.setPlaybackState(playbackState); previousState = state; }
Example 18
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; } }
Example 19
Source File: MediaNotificationManager.java From YouTube-In-Background with MIT License | 4 votes |
private boolean skipBuildNotification(int updatedState) { return mediaController.getMetadata() != null && updatedState != PlaybackStateCompat.STATE_NONE; }
Example 20
Source File: MediaEventResponder.java From Noyze with Apache License 2.0 | 4 votes |
public static Pair<MediaMetadataCompat, PlaybackStateCompat> respond(Context context, Intent intent) { if (null == context || null == intent) return null; String mAction = intent.getAction(); Bundle extras = intent.getExtras(); if (null == extras) extras = Bundle.EMPTY; // In case we've got nothing. MediaMetadataCompat.Builder mBuilder = null; PlaybackStateCompat.Builder pBuilder = null; int state = PlaybackStateCompat.STATE_NONE; long position = 0; LOGI("MediaEventResponder", mAction + ", extras=" + Utils.bundle2string(intent.getExtras())); if (mAction.startsWith("com.amazon.mp3")) { mBuilder = new MediaMetadataCompat.Builder(); pBuilder = new PlaybackStateCompat.Builder(); mBuilder.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, extras.getString("com.amazon.mp3.artist")); mBuilder.putString(MediaMetadataCompat.METADATA_KEY_TITLE, extras.getString("com.amazon.mp3.track")); mBuilder.putString(MediaMetadataCompat.METADATA_KEY_ALBUM, extras.getString("com.amazon.mp3.album")); state = (isPlaying(extras.getInt("com.amazon.mp3.playstate")) ? PlaybackStateCompat.STATE_PLAYING : PlaybackStateCompat.STATE_STOPPED); } else if (mAction.startsWith("com.sonyericsson")) { mBuilder = new MediaMetadataCompat.Builder(); mBuilder.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, extras.getString("ARTIST_NAME")); mBuilder.putString(MediaMetadataCompat.METADATA_KEY_TITLE, extras.getString("TRACK_NAME")); mBuilder.putString(MediaMetadataCompat.METADATA_KEY_ALBUM, extras.getString("ALBUM_NAME")); } else { // This is the default case, standard API check. mBuilder = new MediaMetadataCompat.Builder(); mBuilder.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, extras.getString("artist")); mBuilder.putString(MediaMetadataCompat.METADATA_KEY_ALBUM, extras.getString("album")); if (extras.containsKey("title")) mBuilder.putString(MediaMetadataCompat.METADATA_KEY_TITLE, extras.getString("title")); else if (extras.containsKey("track")) mBuilder.putString(MediaMetadataCompat.METADATA_KEY_TITLE, extras.getString("track")); } // Try the many ways to interpret the play state. if (null == pBuilder) { pBuilder = new PlaybackStateCompat.Builder(); String extraKey = null; if (extras.containsKey("playstate")) extraKey = "playstate"; else if (extras.containsKey("isPlaying")) extraKey = "isPlaying"; else if (extras.containsKey("playing")) extraKey = "playing"; else if (extras.containsKey("state")) extraKey = "state"; // We still haven't given up, check the action. if (TextUtils.isEmpty(extraKey)) { boolean bState = false; if (mAction.endsWith("endofplayback")) bState = false; else if (mAction.endsWith("playbackcomplete")) bState = false; else if (mAction.endsWith("ACTION_PLAYBACK_PAUSE")) // SEMC Legacy bState = false; else if (mAction.endsWith("ACTION_PAUSED")) // SEMC bState = false; else if (mAction.endsWith("ACTION_TRACK_STARTED")) // SEMC Legacy bState = true; else if (mAction.endsWith("ACTION_PLAYBACK_PLAY")) // SEMC bState = true; state = (bState ? PlaybackStateCompat.STATE_PLAYING : PlaybackStateCompat.STATE_STOPPED); } else { state = (extras.getBoolean(extraKey) ? PlaybackStateCompat.STATE_PLAYING : PlaybackStateCompat.STATE_STOPPED); } } // Some extras we might want to use... might. if (extras.containsKey("duration")) mBuilder.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, extras.getLong("duration")); if (extras.containsKey("position")) position = extras.getLong("position"); // Attempt to figure out what app is playing music. pBuilder.setState(state, position, 1.0f); mBuilder.putString(RemoteControlCompat.METADATA_KEY_PACKAGE, packageForAction(mAction)); // Workaround for Google Play Music... not the best :( if (extras.containsKey("previewPlayType") && extras.containsKey("supportsRating") && extras.containsKey("currentContainerId")) mBuilder.putString(RemoteControlCompat.METADATA_KEY_PACKAGE, "com.google.android.music"); // Workaround for Poweramp... should be pretty specific. if (extras.containsKey("com.maxmpz.audioplayer.source")) mBuilder.putString(RemoteControlCompat.METADATA_KEY_PACKAGE, "com.maxmpz.audioplayer"); return Pair.create(mBuilder.build(), pBuilder.build()); }