Search in sources :

Example 26 with MediaControllerCompat

use of android.support.v4.media.session.MediaControllerCompat in project android-UniversalMusicPlayer by googlesamples.

the class TvPlaybackFragment method setupRows.

private void setupRows() {
    PlaybackControlsRowPresenter playbackControlsRowPresenter;
    playbackControlsRowPresenter = new PlaybackControlsRowPresenter(new DescriptionPresenter());
    playbackControlsRowPresenter.setOnActionClickedListener(new OnActionClickedListener() {

        public void onActionClicked(Action action) {
            if (getActivity() == null) {
                return;
            }
            MediaControllerCompat controller = MediaControllerCompat.getMediaController(getActivity());
            if (controller == null) {
                return;
            }
            MediaControllerCompat.TransportControls controls = controller.getTransportControls();
            if (action.getId() == mPlayPauseAction.getId()) {
                if (mPlayPauseAction.getIndex() == PlayPauseAction.PLAY) {
                    controls.play();
                } else {
                    controls.pause();
                }
            } else if (action.getId() == mSkipNextAction.getId()) {
                controls.skipToNext();
                resetPlaybackRow();
            } else if (action.getId() == mSkipPreviousAction.getId()) {
                controls.skipToPrevious();
                resetPlaybackRow();
            }
            if (action instanceof PlaybackControlsRow.MultiAction) {
                ((PlaybackControlsRow.MultiAction) action).nextIndex();
                notifyChanged(action);
            }
        }
    });
    mPresenterSelector.addClassPresenter(PlaybackControlsRow.class, playbackControlsRowPresenter);
}
Also used : AbstractDetailsDescriptionPresenter(android.support.v17.leanback.widget.AbstractDetailsDescriptionPresenter) SkipPreviousAction(android.support.v17.leanback.widget.PlaybackControlsRow.SkipPreviousAction) SkipNextAction(android.support.v17.leanback.widget.PlaybackControlsRow.SkipNextAction) Action(android.support.v17.leanback.widget.Action) PlayPauseAction(android.support.v17.leanback.widget.PlaybackControlsRow.PlayPauseAction) OnActionClickedListener(android.support.v17.leanback.widget.OnActionClickedListener) PlaybackControlsRowPresenter(android.support.v17.leanback.widget.PlaybackControlsRowPresenter) MediaControllerCompat(android.support.v4.media.session.MediaControllerCompat) PlaybackControlsRow(android.support.v17.leanback.widget.PlaybackControlsRow)

Example 27 with MediaControllerCompat

use of android.support.v4.media.session.MediaControllerCompat in project android-UniversalMusicPlayer by googlesamples.

the class MediaIDHelper method isMediaItemPlaying.

/**
 * Determine if media item is playing (matches the currently playing media item).
 *
 * @param context for retrieving the {@link MediaControllerCompat}
 * @param mediaItem to compare to currently playing {@link MediaBrowserCompat.MediaItem}
 * @return boolean indicating whether media item matches currently playing media item
 */
public static boolean isMediaItemPlaying(Activity context, MediaBrowserCompat.MediaItem mediaItem) {
    // Media item is considered to be playing or paused based on the controller's current
    // media id
    MediaControllerCompat controller = MediaControllerCompat.getMediaController(context);
    if (controller != null && controller.getMetadata() != null) {
        String currentPlayingMediaId = controller.getMetadata().getDescription().getMediaId();
        String itemMusicId = MediaIDHelper.extractMusicIDFromMediaID(mediaItem.getDescription().getMediaId());
        if (currentPlayingMediaId != null && TextUtils.equals(currentPlayingMediaId, itemMusicId)) {
            return true;
        }
    }
    return false;
}
Also used : MediaControllerCompat(android.support.v4.media.session.MediaControllerCompat)

Aggregations

MediaControllerCompat (android.support.v4.media.session.MediaControllerCompat)27 FragmentActivity (android.support.v4.app.FragmentActivity)3 MediaSessionCompat (android.support.v4.media.session.MediaSessionCompat)3 PlaybackStateCompat (android.support.v4.media.session.PlaybackStateCompat)3 Intent (android.content.Intent)2 ListRow (android.support.v17.leanback.widget.ListRow)2 ListRowPresenter (android.support.v17.leanback.widget.ListRowPresenter)2 MediaBrowserCompat (android.support.v4.media.MediaBrowserCompat)2 MediaMetadataCompat (android.support.v4.media.MediaMetadataCompat)2 View (android.view.View)2 AbstractDetailsDescriptionPresenter (android.support.v17.leanback.widget.AbstractDetailsDescriptionPresenter)1 Action (android.support.v17.leanback.widget.Action)1 HeaderItem (android.support.v17.leanback.widget.HeaderItem)1 OnActionClickedListener (android.support.v17.leanback.widget.OnActionClickedListener)1 OnItemViewClickedListener (android.support.v17.leanback.widget.OnItemViewClickedListener)1 PlaybackControlsRow (android.support.v17.leanback.widget.PlaybackControlsRow)1 PlayPauseAction (android.support.v17.leanback.widget.PlaybackControlsRow.PlayPauseAction)1 SkipNextAction (android.support.v17.leanback.widget.PlaybackControlsRow.SkipNextAction)1 SkipPreviousAction (android.support.v17.leanback.widget.PlaybackControlsRow.SkipPreviousAction)1 PlaybackControlsRowPresenter (android.support.v17.leanback.widget.PlaybackControlsRowPresenter)1