use of android.support.v4.media.session.MediaControllerCompat in project android-UniversalMusicPlayer by googlesamples.
the class MediaBrowserFragment method onStop.
@Override
public void onStop() {
super.onStop();
MediaBrowserCompat mediaBrowser = mMediaFragmentListener.getMediaBrowser();
if (mediaBrowser != null && mediaBrowser.isConnected() && mMediaId != null) {
mediaBrowser.unsubscribe(mMediaId);
}
MediaControllerCompat controller = ((FragmentActivity) getActivity()).getSupportMediaController();
if (controller != null) {
controller.unregisterCallback(mMediaControllerCallback);
}
this.getActivity().unregisterReceiver(mConnectivityChangeReceiver);
}
use of android.support.v4.media.session.MediaControllerCompat in project android-UniversalMusicPlayer by googlesamples.
the class TvPlaybackFragment method updatePlaybackState.
protected void updatePlaybackState(PlaybackStateCompat state) {
if (mPlaybackControlsRow == null) {
// We only update playback state after we get a valid metadata.
return;
}
mLastPosition = state.getPosition();
mLastPositionUpdateTime = state.getLastPositionUpdateTime();
switch(state.getState()) {
case PlaybackStateCompat.STATE_PLAYING:
startProgressAutomation();
mPlayPauseAction.setIndex(PlayPauseAction.PAUSE);
break;
case PlaybackStateCompat.STATE_PAUSED:
stopProgressAutomation();
mPlayPauseAction.setIndex(PlayPauseAction.PLAY);
break;
}
MediaControllerCompat controller = getActivity().getSupportMediaController();
updatePlayListRow(controller.getQueue());
mRowsAdapter.notifyArrayItemRangeChanged(mRowsAdapter.indexOf(mPlaybackControlsRow), 1);
}
use of android.support.v4.media.session.MediaControllerCompat in project android-UniversalMusicPlayer by googlesamples.
the class MediaNotificationManager method updateSessionToken.
/**
* Update the state based on a change on the session token. Called either when
* we are running for the first time or when the media session owner has destroyed the session
* (see {@link android.media.session.MediaController.Callback#onSessionDestroyed()})
*/
private void updateSessionToken() throws RemoteException {
MediaSessionCompat.Token freshToken = mService.getSessionToken();
if (mSessionToken == null && freshToken != null || mSessionToken != null && !mSessionToken.equals(freshToken)) {
if (mController != null) {
mController.unregisterCallback(mCb);
}
mSessionToken = freshToken;
if (mSessionToken != null) {
mController = new MediaControllerCompat(mService, mSessionToken);
mTransportControls = mController.getTransportControls();
if (mStarted) {
mController.registerCallback(mCb);
}
}
}
}
use of android.support.v4.media.session.MediaControllerCompat in project android-UniversalMusicPlayer by googlesamples.
the class FullScreenPlayerActivity method connectToSession.
private void connectToSession(MediaSessionCompat.Token token) throws RemoteException {
MediaControllerCompat mediaController = new MediaControllerCompat(FullScreenPlayerActivity.this, token);
if (mediaController.getMetadata() == null) {
finish();
return;
}
setSupportMediaController(mediaController);
mediaController.registerCallback(mCallback);
PlaybackStateCompat state = mediaController.getPlaybackState();
updatePlaybackState(state);
MediaMetadataCompat metadata = mediaController.getMetadata();
if (metadata != null) {
updateMediaDescription(metadata.getDescription());
updateDuration(metadata);
}
updateProgress();
if (state != null && (state.getState() == PlaybackStateCompat.STATE_PLAYING || state.getState() == PlaybackStateCompat.STATE_BUFFERING)) {
scheduleSeekbarUpdate();
}
}
use of android.support.v4.media.session.MediaControllerCompat in project android-UniversalMusicPlayer by googlesamples.
the class TvBrowseFragment method initializeWithMediaId.
public void initializeWithMediaId(String mediaId) {
LogHelper.d(TAG, "subscribeToData");
// fetch browsing information to fill the listview:
mMediaBrowser = mMediaFragmentListener.getMediaBrowser();
if (mediaId == null) {
mediaId = mMediaBrowser.getRoot();
}
subscribeToMediaId(mediaId, mSubscriptionCallback);
// Add MediaController callback so we can redraw the list when metadata changes:
MediaControllerCompat mediaController = getActivity().getSupportMediaController();
if (mediaController != null) {
mediaController.registerCallback(mMediaControllerCallback);
}
}
Aggregations