Search in sources :

Example 1 with MediaControllerCompat

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;
    }
}
Also used : FragmentActivity(android.support.v4.app.FragmentActivity) PlaybackStateCompat(android.support.v4.media.session.PlaybackStateCompat) MediaControllerCompat(android.support.v4.media.session.MediaControllerCompat)

Example 2 with MediaControllerCompat

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();
}
Also used : MediaControllerCompat(android.support.v4.media.session.MediaControllerCompat)

Example 3 with MediaControllerCompat

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();
}
Also used : MediaControllerCompat(android.support.v4.media.session.MediaControllerCompat)

Example 4 with MediaControllerCompat

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);
    }
}
Also used : MediaControllerCompat(android.support.v4.media.session.MediaControllerCompat)

Example 5 with MediaControllerCompat

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);
    }
}
Also used : MediaControllerCompat(android.support.v4.media.session.MediaControllerCompat)

Aggregations

MediaControllerCompat (android.support.v4.media.session.MediaControllerCompat)35 PlaybackStateCompat (android.support.v4.media.session.PlaybackStateCompat)7 Intent (android.content.Intent)5 MediaMetadataCompat (android.support.v4.media.MediaMetadataCompat)5 MediaSessionCompat (android.support.v4.media.session.MediaSessionCompat)5 ComponentName (android.content.ComponentName)3 FragmentActivity (android.support.v4.app.FragmentActivity)3 View (android.view.View)3 PendingIntent (android.app.PendingIntent)2 Bundle (android.os.Bundle)2 RemoteException (android.os.RemoteException)2 ListRow (android.support.v17.leanback.widget.ListRow)2 ListRowPresenter (android.support.v17.leanback.widget.ListRowPresenter)2 MediaBrowserCompat (android.support.v4.media.MediaBrowserCompat)2 MediaDescriptionCompat (android.support.v4.media.MediaDescriptionCompat)2 ServiceConnection (android.content.ServiceConnection)1 Bitmap (android.graphics.Bitmap)1 IBinder (android.os.IBinder)1 CallSuper (android.support.annotation.CallSuper)1 VideoSupportFragmentGlueHost (android.support.v17.leanback.app.VideoSupportFragmentGlueHost)1