@Override public void onSessionDestroyed() { super.onSessionDestroyed(); Log.d(TAG, "Session was destroyed, resetting to the new session token"); try { updateSessionToken(); } catch (RemoteException e) { Log.e(TAG, "could not connect media controller", e); } } };
@Override public void onPlaybackStateChanged(PlaybackStateCompat state) { super.onPlaybackStateChanged(state); // If there's an ongoing animation, stop it now. if (mProgressAnimator != null) { mProgressAnimator.cancel(); mProgressAnimator = null; } final int progress = state != null ? (int) state.getPosition() : 0; setProgress(progress); // If the media is playing then the seekbar should follow it, and the easiest // way to do that is to create a ValueAnimator to update it so the bar reaches // the end of the media the same time as playback gets there (or close enough). if (state != null && state.getState() == PlaybackStateCompat.STATE_PLAYING) { final int timeToEnd = (int) ((getMax() - progress) / state.getPlaybackSpeed()); mProgressAnimator = ValueAnimator.ofInt(progress, getMax()) .setDuration(timeToEnd); mProgressAnimator.setInterpolator(new LinearInterpolator()); mProgressAnimator.addUpdateListener(this); mProgressAnimator.start(); } }
@Override public void onMetadataChanged(MediaMetadataCompat metadata) { super.onMetadataChanged(metadata); mMetadata = metadata; Notification notification = createNotification(); if (notification != null) { mNotificationManager.notify(NOTIFICATION_ID, notification); } }
@Override public void onPlaybackStateChanged(PlaybackStateCompat state) { super.onPlaybackStateChanged(state); playbackState = state != null ? state : EMPTY_PLAYBACK_STATE;
@Override public void onMetadataChanged(MediaMetadataCompat metadata) { super.onMetadataChanged(metadata); nowPlaying = metadata != null ? metadata : NOTHING_PLAYING; //ηΆζηε¬ CopyOnWriteArrayList<OnPlayerEventListener> mPlayerEventListeners = MusicManager.getInstance().getPlayerEventListeners(); if (metadata != null) { SongInfo songInfo = null; for (OnPlayerEventListener listener : mPlayerEventListeners) { List<SongInfo> songInfos = MusicProvider.getInstance().getSongInfos(); for (SongInfo info : songInfos) { if (info.getSongId().equals(metadata.getString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID))) { songInfo = info; break; } } listener.onMusicSwitch(songInfo); } } }
@Override public void onConnected() { Log.d(TAG, "MediaBrowser connected"); try { MediaControllerCompat mediaController = new MediaControllerCompat( TomahawkMainActivity.this, mMediaBrowser.getSessionToken()); setSupportMediaController(mediaController); mediaController.registerCallback(mMediaCallback); mPlaybackPanel.setMediaController(mediaController); mMediaCallback.onPlaybackStateChanged(mediaController.getPlaybackState()); ContentHeaderFragment.MediaControllerConnectedEvent event = new ContentHeaderFragment.MediaControllerConnectedEvent(); EventBus.getDefault().post(event); } catch (RemoteException e) { Log.e(TAG, "Could not connect media controller: ", e); } } };
public void registerCallback(Callback callback) { if (callback != null) { mCallbackList.add(callback); // Update with the latest metadata/playback state. if (mMediaController != null) { final MediaMetadataCompat metadata = mMediaController.getMetadata(); if (metadata != null) { callback.onMetadataChanged(metadata); } final PlaybackStateCompat playbackState = mMediaController.getPlaybackState(); if (playbackState != null) { callback.onPlaybackStateChanged(playbackState); } } } }
@Override public void onPlaybackStateChanged(PlaybackStateCompat state) { super.onPlaybackStateChanged(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); } } }
@Override public void onPlaybackStateChanged(Object stateObj) { Callback.this.onPlaybackStateChanged( PlaybackStateCompat.fromPlaybackState(stateObj)); }
@Override public void onSessionDestroyed() { super.onSessionDestroyed(); }
@Override public void onSessionDestroyed() { super.onSessionDestroyed(); }
@Override public void onSessionDestroyed() { Callback.this.onSessionDestroyed(); }
@Override public void onPlaybackStateChanged(PlaybackStateCompat state) { super.onPlaybackStateChanged(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); } } }
@Override public void onSessionEvent(String event, Bundle extras) { Callback.this.onSessionEvent(event, extras); }
@Override public void perform(@NonNull Callback callback) { callback.onPlaybackStateChanged(state); } });
@Override public void onQueueChanged(List<MediaSessionCompat.QueueItem> queue) { super.onQueueChanged(queue); } }
@Override public void onSessionDestroyed() { super.onSessionDestroyed(); try { updateSessionToken(); } catch (RemoteException e) { e.printStackTrace(); } } };
@Override public void onSessionDestroyed() { super.onSessionDestroyed(); mediaBrowserConnectionCallback.onConnectionSuspended(); } }
@Override public void onSessionDestroyed() { super.onSessionDestroyed(); try { updateSessionToken(); } catch (RemoteException e) { e.printStackTrace(); } } };
@Override public void perform(@NonNull Callback callback) { callback.onPlaybackStateChanged(null); } });