use of android.support.v4.media.session.MediaControllerCompat in project android-UniversalMusicPlayer by googlesamples.
the class MediaItemViewHolder method getStateFromController.
public static int getStateFromController(Context context) {
MediaControllerCompat controller = ((FragmentActivity) context).getSupportMediaController();
PlaybackStateCompat pbState = controller.getPlaybackState();
if (pbState == null || pbState.getState() == PlaybackStateCompat.STATE_ERROR) {
return MediaItemViewHolder.STATE_NONE;
} else if (pbState.getState() == PlaybackStateCompat.STATE_PLAYING) {
return MediaItemViewHolder.STATE_PLAYING;
} else {
return MediaItemViewHolder.STATE_PAUSED;
}
}
use of android.support.v4.media.session.MediaControllerCompat in project android-UniversalMusicPlayer by googlesamples.
the class BaseActivity method onStop.
@Override
protected void onStop() {
super.onStop();
LogHelper.d(TAG, "Activity onStop");
MediaControllerCompat controllerCompat = MediaControllerCompat.getMediaController(this);
if (controllerCompat != null) {
controllerCompat.unregisterCallback(mMediaControllerCallback);
}
mMediaBrowser.disconnect();
}
use of android.support.v4.media.session.MediaControllerCompat in project android-UniversalMusicPlayer by googlesamples.
the class BaseActivity method connectToSession.
private void connectToSession(MediaSessionCompat.Token token) throws RemoteException {
MediaControllerCompat mediaController = new MediaControllerCompat(this, token);
MediaControllerCompat.setMediaController(this, mediaController);
mediaController.registerCallback(mMediaControllerCallback);
if (shouldShowControls()) {
showPlaybackControls();
} else {
LogHelper.d(TAG, "connectionCallback.onConnected: " + "hiding controls because metadata is null");
hidePlaybackControls();
}
if (mControlsFragment != null) {
mControlsFragment.onConnected();
}
onMediaControllerConnected();
}
use of android.support.v4.media.session.MediaControllerCompat in project android-UniversalMusicPlayer by googlesamples.
the class FullScreenPlayerActivity method onStop.
@Override
public void onStop() {
super.onStop();
if (mMediaBrowser != null) {
mMediaBrowser.disconnect();
}
MediaControllerCompat controllerCompat = MediaControllerCompat.getMediaController(FullScreenPlayerActivity.this);
if (controllerCompat != null) {
controllerCompat.unregisterCallback(mCallback);
}
}
use of android.support.v4.media.session.MediaControllerCompat in project android-UniversalMusicPlayer by googlesamples.
the class MediaBrowserFragment method onConnected.
// Called when the MediaBrowser is connected. This method is either called by the
// fragment.onStart() or explicitly by the activity in the case where the connection
// completes after the onStart()
public void onConnected() {
if (isDetached()) {
return;
}
mMediaId = getMediaId();
if (mMediaId == null) {
mMediaId = mMediaFragmentListener.getMediaBrowser().getRoot();
}
updateTitle();
// Unsubscribing before subscribing is required if this mediaId already has a subscriber
// on this MediaBrowser instance. Subscribing to an already subscribed mediaId will replace
// the callback, but won't trigger the initial callback.onChildrenLoaded.
//
// This is temporary: A bug is being fixed that will make subscribe
// consistently call onChildrenLoaded initially, no matter if it is replacing an existing
// subscriber or not. Currently this only happens if the mediaID has no previous
// subscriber or if the media content changes on the service side, so we need to
// unsubscribe first.
mMediaFragmentListener.getMediaBrowser().unsubscribe(mMediaId);
mMediaFragmentListener.getMediaBrowser().subscribe(mMediaId, mSubscriptionCallback);
// Add MediaController callback so we can redraw the list when metadata changes:
MediaControllerCompat controller = MediaControllerCompat.getMediaController(getActivity());
if (controller != null) {
controller.registerCallback(mMediaControllerCallback);
}
}
Aggregations