Search in sources :

Example 1 with PlaybackControlsRowPresenter

use of android.support.v17.leanback.widget.PlaybackControlsRowPresenter 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 = getActivity().getSupportMediaController();
            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)

Aggregations

AbstractDetailsDescriptionPresenter (android.support.v17.leanback.widget.AbstractDetailsDescriptionPresenter)1 Action (android.support.v17.leanback.widget.Action)1 OnActionClickedListener (android.support.v17.leanback.widget.OnActionClickedListener)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 MediaControllerCompat (android.support.v4.media.session.MediaControllerCompat)1