androidx.leanback.widget.PlaybackControlsRow Java Examples

The following examples show how to use androidx.leanback.widget.PlaybackControlsRow. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VideoMediaPlayerGlue.java    From tv-samples with Apache License 2.0 6 votes vote down vote up
private void notifyActionChanged(PlaybackControlsRow.MultiAction action) {
    int index = -1;
    if (getPrimaryActionsAdapter() != null) {
        index = getPrimaryActionsAdapter().indexOf(action);
    }
    if (index >= 0) {
        getPrimaryActionsAdapter().notifyArrayItemRangeChanged(index, 1);
    } else {
        if (getSecondaryActionsAdapter() != null) {
            index = getSecondaryActionsAdapter().indexOf(action);
            if (index >= 0) {
                getSecondaryActionsAdapter().notifyArrayItemRangeChanged(index, 1);
            }
        }
    }
}
 
Example #2
Source File: VideoPlayerGlue.java    From androidtv-Leanback with Apache License 2.0 6 votes vote down vote up
private void dispatchAction(Action action) {
    // Primary actions are handled manually.
    if (action == mRewindAction) {
        rewind();
    } else if (action == mFastForwardAction) {
        fastForward();
    } else if (action instanceof PlaybackControlsRow.MultiAction) {
        PlaybackControlsRow.MultiAction multiAction = (PlaybackControlsRow.MultiAction) action;
        multiAction.nextIndex();
        // Notify adapter of action changes to handle secondary actions, such as, thumbs up/down
        // and repeat.
        notifyActionChanged(
                multiAction,
                (ArrayObjectAdapter) getControlsRow().getSecondaryActionsAdapter());
    }
}
 
Example #3
Source File: VideoPlayerGlue.java    From androidtv-Leanback with Apache License 2.0 6 votes vote down vote up
public VideoPlayerGlue(
        Context context,
        LeanbackPlayerAdapter playerAdapter,
        OnActionClickedListener actionListener) {
    super(context, playerAdapter);

    mActionListener = actionListener;

    mSkipPreviousAction = new PlaybackControlsRow.SkipPreviousAction(context);
    mSkipNextAction = new PlaybackControlsRow.SkipNextAction(context);
    mFastForwardAction = new PlaybackControlsRow.FastForwardAction(context);
    mRewindAction = new PlaybackControlsRow.RewindAction(context);

    mThumbsUpAction = new PlaybackControlsRow.ThumbsUpAction(context);
    mThumbsUpAction.setIndex(PlaybackControlsRow.ThumbsUpAction.INDEX_OUTLINE);
    mThumbsDownAction = new PlaybackControlsRow.ThumbsDownAction(context);
    mThumbsDownAction.setIndex(PlaybackControlsRow.ThumbsDownAction.INDEX_OUTLINE);
    mRepeatAction = new PlaybackControlsRow.RepeatAction(context);
}
 
Example #4
Source File: CustomPlaybackTransportControlGlue.java    From jellyfin-androidtv with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onActionClicked(Action action) {
    if (action == playPauseAction) {
        if (playPauseAction.getIndex() == PlaybackControlsRow.PlayPauseAction.INDEX_PAUSE) {
            getPlayerAdapter().pause();
            playPauseAction.setIndex(PlaybackControlsRow.PlayPauseAction.INDEX_PLAY);
        } else if (playPauseAction.getIndex() == PlaybackControlsRow.PlayPauseAction.INDEX_PLAY) {
            getPlayerAdapter().play();
            playPauseAction.setIndex(PlaybackControlsRow.PlayPauseAction.INDEX_PAUSE);
        }
    } else if (action == rewindAction) {
        getPlayerAdapter().rewind();
    } else if (action == fastForwardAction) {
        getPlayerAdapter().fastForward();
    } else if (action == skipNextAction) {
        getPlayerAdapter().next();
    }
    notifyActionChanged(action);
}
 
Example #5
Source File: CustomPlaybackTransportControlGlue.java    From jellyfin-androidtv with GNU General Public License v2.0 6 votes vote down vote up
private void initActions(Context context) {
    playPauseAction = new PlaybackControlsRow.PlayPauseAction(context);
    rewindAction = new PlaybackControlsRow.RewindAction(context);
    fastForwardAction = new PlaybackControlsRow.FastForwardAction(context);
    skipNextAction = new PlaybackControlsRow.SkipNextAction(context);
    selectAudioAction = new SelectAudioAction(context, this);
    closedCaptionsAction = new ClosedCaptionsAction(context, this);
    adjustAudioDelayAction = new AdjustAudioDelayAction(context, this);
    zoomAction = new ZoomAction(context, this);
    chapterAction = new ChapterAction(context, this);

    previousLiveTvChannelAction = new PreviousLiveTvChannelAction(context, this);
    channelBarChannelAction = new ChannelBarChannelAction(context, this);
    guideAction = new GuideAction(context, this);
    recordAction = new RecordAction(context, this);
}
 
Example #6
Source File: VideoPlayerGlue.java    From tv-samples with Apache License 2.0 6 votes vote down vote up
private void dispatchAction(Action action) {
    // Primary actions are handled manually.
    if (action == mRewindAction) {
        rewind();
    } else if (action == mFastForwardAction) {
        fastForward();
    } else if (action instanceof PlaybackControlsRow.MultiAction) {
        PlaybackControlsRow.MultiAction multiAction = (PlaybackControlsRow.MultiAction) action;
        multiAction.nextIndex();
        // Notify adapter of action changes to handle secondary actions, such as, thumbs up/down
        // and repeat.
        notifyActionChanged(
                multiAction,
                (ArrayObjectAdapter) getControlsRow().getSecondaryActionsAdapter());
    }
}
 
Example #7
Source File: VideoPlayerGlue.java    From tv-samples with Apache License 2.0 6 votes vote down vote up
public VideoPlayerGlue(
        Context context,
        LeanbackPlayerAdapter playerAdapter,
        OnActionClickedListener actionListener) {
    super(context, playerAdapter);

    mActionListener = actionListener;

    mSkipPreviousAction = new PlaybackControlsRow.SkipPreviousAction(context);
    mSkipNextAction = new PlaybackControlsRow.SkipNextAction(context);
    mFastForwardAction = new PlaybackControlsRow.FastForwardAction(context);
    mRewindAction = new PlaybackControlsRow.RewindAction(context);

    mThumbsUpAction = new PlaybackControlsRow.ThumbsUpAction(context);
    mThumbsUpAction.setIndex(PlaybackControlsRow.ThumbsUpAction.INDEX_OUTLINE);
    mThumbsDownAction = new PlaybackControlsRow.ThumbsDownAction(context);
    mThumbsDownAction.setIndex(PlaybackControlsRow.ThumbsDownAction.INDEX_OUTLINE);
    mRepeatAction = new PlaybackControlsRow.RepeatAction(context);
}
 
Example #8
Source File: VideoConsumptionExampleWithExoPlayerFragment.java    From tv-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ExoPlayerAdapter playerAdapter = new ExoPlayerAdapter(getActivity());
    playerAdapter.setAudioStreamType(AudioManager.USE_DEFAULT_STREAM_TYPE);
    mMediaPlayerGlue = new VideoMediaPlayerGlue(getActivity(), playerAdapter);
    mMediaPlayerGlue.setHost(mHost);
    AudioManager audioManager = (AudioManager) getActivity()
            .getSystemService(Context.AUDIO_SERVICE);
    if (audioManager.requestAudioFocus(mOnAudioFocusChangeListener, AudioManager.STREAM_MUSIC,
            AudioManager.AUDIOFOCUS_GAIN) != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
        Log.w(TAG, "video player cannot obtain audio focus!");
    }

    mMediaPlayerGlue.setMode(PlaybackControlsRow.RepeatAction.NONE);
    MediaMetaData intentMetaData = getActivity().getIntent().getParcelableExtra(
            VideoExampleActivity.TAG);
    if (intentMetaData != null) {
        mMediaPlayerGlue.setTitle(intentMetaData.getMediaTitle());
        mMediaPlayerGlue.setSubtitle(intentMetaData.getMediaArtistName());
        mMediaPlayerGlue.getPlayerAdapter().setDataSource(
                Uri.parse(intentMetaData.getMediaSourcePath()));
    } else {
        mMediaPlayerGlue.setTitle("Diving with Sharks");
        mMediaPlayerGlue.setSubtitle("A Googler");
        mMediaPlayerGlue.getPlayerAdapter().setDataSource(Uri.parse(URL));
    }
    PlaybackSeekDiskDataProvider.setDemoSeekProvider(mMediaPlayerGlue);
    playWhenReady(mMediaPlayerGlue);
    setBackgroundType(BG_LIGHT);
}
 
Example #9
Source File: VideoPlayerGlue.java    From androidtv-Leanback with Apache License 2.0 5 votes vote down vote up
private void notifyActionChanged(
        PlaybackControlsRow.MultiAction action, ArrayObjectAdapter adapter) {
    if (adapter != null) {
        int index = adapter.indexOf(action);
        if (index >= 0) {
            adapter.notifyArrayItemRangeChanged(index, 1);
        }
    }
}
 
Example #10
Source File: VideoPlayerGlue.java    From tv-samples with Apache License 2.0 5 votes vote down vote up
private void notifyActionChanged(
        PlaybackControlsRow.MultiAction action, ArrayObjectAdapter adapter) {
    if (adapter != null) {
        int index = adapter.indexOf(action);
        if (index >= 0) {
            adapter.notifyArrayItemRangeChanged(index, 1);
        }
    }
}
 
Example #11
Source File: VideoMediaPlayerGlue.java    From tv-samples with Apache License 2.0 5 votes vote down vote up
public VideoMediaPlayerGlue(Activity context, T impl) {
    super(context, impl);
    mClosedCaptioningAction = new PlaybackControlsRow.ClosedCaptioningAction(context);
    mThumbsUpAction = new PlaybackControlsRow.ThumbsUpAction(context);
    mThumbsUpAction.setIndex(PlaybackControlsRow.ThumbsUpAction.OUTLINE);
    mThumbsDownAction = new PlaybackControlsRow.ThumbsDownAction(context);
    mThumbsDownAction.setIndex(PlaybackControlsRow.ThumbsDownAction.OUTLINE);
    mRepeatAction = new PlaybackControlsRow.RepeatAction(context);
    mPipAction = new PlaybackControlsRow.PictureInPictureAction(context);
}
 
Example #12
Source File: VideoConsumptionExampleFragment.java    From tv-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mMediaPlayerGlue = new VideoMediaPlayerGlue(getActivity(),
            new MediaPlayerAdapter(getActivity()));
    mMediaPlayerGlue.setHost(mHost);
    AudioManager audioManager = (AudioManager) getActivity()
            .getSystemService(Context.AUDIO_SERVICE);
    if (audioManager.requestAudioFocus(mOnAudioFocusChangeListener, AudioManager.STREAM_MUSIC,
            AudioManager.AUDIOFOCUS_GAIN) != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
        Log.w(TAG, "video player cannot obtain audio focus!");
    }

    mMediaPlayerGlue.setMode(PlaybackControlsRow.RepeatAction.NONE);
    MediaMetaData intentMetaData = getActivity().getIntent().getParcelableExtra(
            VideoExampleActivity.TAG);
    if (intentMetaData != null) {
        mMediaPlayerGlue.setTitle(intentMetaData.getMediaTitle());
        mMediaPlayerGlue.setSubtitle(intentMetaData.getMediaArtistName());
        mMediaPlayerGlue.getPlayerAdapter().setDataSource(
                Uri.parse(intentMetaData.getMediaSourcePath()));
    } else {
        mMediaPlayerGlue.setTitle("Diving with Sharks");
        mMediaPlayerGlue.setSubtitle("A Googler");
        mMediaPlayerGlue.getPlayerAdapter().setDataSource(Uri.parse(URL));
    }
    PlaybackSeekDiskDataProvider.setDemoSeekProvider(mMediaPlayerGlue);
    playWhenReady(mMediaPlayerGlue);
    setBackgroundType(BG_LIGHT);
}
 
Example #13
Source File: MediaPlayerGlue.java    From tv-samples with Apache License 2.0 5 votes vote down vote up
@Override public void onActionClicked(Action action) {
    if (action instanceof PlaybackControlsRow.ShuffleAction
            || action instanceof PlaybackControlsRow.RepeatAction) {
        ((PlaybackControlsRow.MultiAction) action).nextIndex();
        notifySecondaryActionChanged(action);
    } else if (action == mThumbsUpAction) {
        if (mThumbsUpAction.getIndex() == PlaybackControlsRow.ThumbsAction.SOLID) {
            mThumbsUpAction.setIndex(PlaybackControlsRow.ThumbsAction.OUTLINE);
            notifySecondaryActionChanged(mThumbsUpAction);
        } else {
            mThumbsUpAction.setIndex(PlaybackControlsRow.ThumbsAction.SOLID);
            mThumbsDownAction.setIndex(PlaybackControlsRow.ThumbsAction.OUTLINE);
            notifySecondaryActionChanged(mThumbsUpAction);
            notifySecondaryActionChanged(mThumbsDownAction);
        }
    } else if (action == mThumbsDownAction) {
        if (mThumbsDownAction.getIndex() == PlaybackControlsRow.ThumbsAction.SOLID) {
            mThumbsDownAction.setIndex(PlaybackControlsRow.ThumbsAction.OUTLINE);
            notifySecondaryActionChanged(mThumbsDownAction);
        } else {
            mThumbsDownAction.setIndex(PlaybackControlsRow.ThumbsAction.SOLID);
            mThumbsUpAction.setIndex(PlaybackControlsRow.ThumbsAction.OUTLINE);
            notifySecondaryActionChanged(mThumbsUpAction);
            notifySecondaryActionChanged(mThumbsDownAction);
        }
    } else {
        super.onActionClicked(action);
    }
}
 
Example #14
Source File: MediaPlayerGlue.java    From tv-samples with Apache License 2.0 5 votes vote down vote up
public MediaPlayerGlue(Context context) {
    super(context, new int[]{1});
    mShuffleAction = new PlaybackControlsRow.ShuffleAction(getContext());
    mRepeatAction = new PlaybackControlsRow.RepeatAction(getContext());
    mThumbsDownAction = new PlaybackControlsRow.ThumbsDownAction(getContext());
    mThumbsUpAction = new PlaybackControlsRow.ThumbsUpAction(getContext());
    mThumbsDownAction.setIndex(PlaybackControlsRow.ThumbsAction.OUTLINE);
    mThumbsUpAction.setIndex(PlaybackControlsRow.ThumbsAction.OUTLINE);
}
 
Example #15
Source File: MusicMediaPlayerGlue.java    From tv-samples with Apache License 2.0 5 votes vote down vote up
public static int mapServiceRepeatStateToActionIndex(int serviceRepeatState) {
    if (serviceRepeatState == MusicPlaybackService.MEDIA_ACTION_REPEAT_ONE) {
        return PlaybackControlsRow.RepeatAction.ONE;
    } else if (serviceRepeatState == MusicPlaybackService.MEDIA_ACTION_REPEAT_ALL) {
        return PlaybackControlsRow.RepeatAction.ALL;
    } else {
        return PlaybackControlsRow.RepeatAction.NONE;
    }
}
 
Example #16
Source File: MusicMediaPlayerGlue.java    From tv-samples with Apache License 2.0 5 votes vote down vote up
public static int mapActionIndexToServiceRepeatState(int index) {
    if (index == PlaybackControlsRow.RepeatAction.ONE) {
        return MusicPlaybackService.MEDIA_ACTION_REPEAT_ONE;
    } else if (index == PlaybackControlsRow.RepeatAction.ALL) {
        return MusicPlaybackService.MEDIA_ACTION_REPEAT_ALL;
    } else {
        return MusicPlaybackService.MEDIA_ACTION_NO_REPEAT;
    }
}
 
Example #17
Source File: MusicMediaPlayerGlue.java    From tv-samples with Apache License 2.0 5 votes vote down vote up
@Override public void onActionClicked(Action action) {
    // If either 'Shuffle' or 'Repeat' has been clicked we need to make sure the acitons index
    // is incremented and the UI updated such that we can display the new state.
    super.onActionClicked(action);
    if (action instanceof PlaybackControlsRow.RepeatAction) {
        int index = ((PlaybackControlsRow.RepeatAction) action).getIndex();
        if (mPlaybackService != null) {
            mPlaybackService.setRepeatState(mapActionIndexToServiceRepeatState(index));
        }
    }
}
 
Example #18
Source File: VideoMediaPlayerGlue.java    From tv-samples with Apache License 2.0 5 votes vote down vote up
@Override
protected void onPlayCompleted() {
    super.onPlayCompleted();
    mHandler.post(new Runnable() {
        @Override
        public void run() {
            if (mRepeatAction.getIndex() != PlaybackControlsRow.RepeatAction.NONE) {
                play();
            }
        }
    });
}
 
Example #19
Source File: VideoMediaPlayerGlue.java    From tv-samples with Apache License 2.0 5 votes vote down vote up
private void dispatchAction(Action action) {
    if (action == mPipAction) {
        ((Activity) getContext()).enterPictureInPictureMode();
    } else {
        Toast.makeText(getContext(), action.toString(), Toast.LENGTH_SHORT).show();
        PlaybackControlsRow.MultiAction multiAction = (PlaybackControlsRow.MultiAction) action;
        multiAction.nextIndex();
        notifyActionChanged(multiAction);
    }
}
 
Example #20
Source File: CustomPlaybackTransportControlGlue.java    From jellyfin-androidtv with GNU General Public License v2.0 4 votes vote down vote up
void setInitialPlaybackDrawable() {
    playPauseAction.setIndex(PlaybackControlsRow.PlayPauseAction.INDEX_PAUSE);
    notifyActionChanged(playPauseAction);
}
 
Example #21
Source File: CustomPlaybackTransportControlGlue.java    From jellyfin-androidtv with GNU General Public License v2.0 4 votes vote down vote up
void updatePlayState() {
    playPauseAction.setIndex(isPlaying() ? PlaybackControlsRow.PlayPauseAction.INDEX_PAUSE : PlaybackControlsRow.PlayPauseAction.INDEX_PLAY);
    notifyActionChanged(playPauseAction);
}