private void setupUI() { VideoFragment videoFragment = (VideoFragment) getFragmentManager().findFragmentById(R.id.video_fragment); mGlue = new VideoFragmentGlueHost(videoFragment); mGlue.setSurfaceHolderCallback(this); mGlue.setOnActionClickedListener(this); mControlsRow = new PlaybackControlsRow(mSelectedLink); ArrayObjectAdapter adapter = new ArrayObjectAdapter(new ControlButtonPresenterSelector()); mPlayPauseAction = new PlaybackControlsRow.PlayPauseAction(this); mPlayPauseAction.nextIndex(); // set to play adapter.add(new PlaybackControlsRow.RewindAction(this)); adapter.add(mPlayPauseAction); adapter.add(new PlaybackControlsRow.FastForwardAction(this)); mControlsRow.setPrimaryActionsAdapter(adapter); PlaybackControlsRowPresenter presenter = new PlaybackControlsRowPresenter(new DetailsPresenter()); mGlue.setPlaybackRow(mControlsRow); mGlue.setPlaybackRowPresenter(presenter); }
@Override public PlaybackControlsRowPresenter createControlsRowAndPresenter() { PlaybackControlsRowPresenter presenter = super.createControlsRowAndPresenter(); adapter = new ArrayObjectAdapter(new ControlButtonPresenterSelector()); getControlsRow().setSecondaryActionsAdapter(adapter); mFastForwardAction = (PlaybackControlsRow.FastForwardAction) getPrimaryActionsAdapter() .lookup(ACTION_FAST_FORWARD); mRewindAction = (PlaybackControlsRow.RewindAction) getPrimaryActionsAdapter() .lookup(ACTION_REWIND); presenter.setOnActionClickedListener(new OnActionClickedListener() { @Override public void onActionClicked(Action action) { dispatchAction(action); } }); return presenter; }
@TargetApi(VERSION_CODES.N) public void dispatchAction(Action action) { if (action instanceof PlaybackControlsRow.MultiAction) { PlaybackControlsRow.MultiAction multiAction = (PlaybackControlsRow.MultiAction) action; multiAction.nextIndex(); notifyActionChanged(multiAction); } if (action == mFastForwardAction) { mTransportControls.fastForward(); } else if (action == mRewindAction) { mTransportControls.rewind(); } else if (action.getId() == mPipAction.getId()) { ((Activity) getContext()).enterPictureInPictureMode(); } else { super.onActionClicked(action); } }
@Override public void onActionClicked(@NonNull Action action) { if (action.getId() == mPlayPauseAction.getId()) { invokeTogglePlaybackAction(mPlayPauseAction.getIndex() == PlayPauseAction.PLAY); } else if (action.getId() == mScaleVideoAction.getId()) { invokeScaleVideoAction(); } else if (action.getId() == mClosedCaptioningAction.getId()) { invokeOpenSubtitleSettingsAction(); } if (mSkipPreviousAction != null && action.getId() == mSkipPreviousAction.getId()) { playSelectedEpisode(mPreviousEpisode); } if (mSkipNextAction != null && action.getId() == mSkipNextAction.getId()) { playSelectedEpisode(mNextEpisode); } if (action instanceof PlaybackControlsRow.MultiAction) { notifyPlaybackControlActionChanged(action); } }
private void setupPlaybackControlItemsToInitialisingState() { mRowsAdapter.clear(); mPlaybackControlsRow = new PlaybackControlsRow(mStreamInfo); mPlaybackControlsRow.setCurrentTime(0); mPlaybackControlsRow.setBufferedProgress(0); ControlButtonPresenterSelector presenterSelector = new ControlButtonPresenterSelector(); mPrimaryActionsAdapter = new ArrayObjectAdapter(presenterSelector); mPlaybackControlsRow.setPrimaryActionsAdapter(mPrimaryActionsAdapter); Activity activity = getActivity(); mPlayPauseAction = new PlayPauseAction(activity); mPrimaryActionsAdapter.add(mPlayPauseAction); setupSecondaryRowPlaybackControl(presenterSelector); mRowsAdapter.add(mPlaybackControlsRow); mRowsAdapter.notifyArrayItemRangeChanged(0, mRowsAdapter.size()); }
private void setupPrimaryRowPlaybackControl(@NonNull ControlButtonPresenterSelector presenterSelector) { mPrimaryActionsAdapter = new ArrayObjectAdapter(presenterSelector); mPlaybackControlsRow.setPrimaryActionsAdapter(mPrimaryActionsAdapter); Activity activity = getActivity(); mPlayPauseAction = new PlayPauseAction(activity); mFastForwardAction = new FastForwardAction(activity); mRewindAction = new RewindAction(activity); if (mPreviousEpisode != null) { mSkipPreviousAction = new PlaybackControlsRow.SkipPreviousAction(activity); mPrimaryActionsAdapter.add(mSkipPreviousAction); } // Add main controls to primary adapter. mPrimaryActionsAdapter.add(mRewindAction); mPrimaryActionsAdapter.add(mPlayPauseAction); mPrimaryActionsAdapter.add(mFastForwardAction); if (mNextEpisode != null) { mSkipNextAction = new PlaybackControlsRow.SkipNextAction(activity); mPrimaryActionsAdapter.add(mSkipNextAction); } }
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); } } } }
private void addPlaybackControlsRow(MediaMetadata metadata) { mPlaybackControlsRow = new PlaybackControlsRow(new MutableMediaMetadataHolder(metadata)); mRowsAdapter.add(mPlaybackControlsRow); resetPlaybackRow(); ControlButtonPresenterSelector presenterSelector = new ControlButtonPresenterSelector(); mPrimaryActionsAdapter = new ArrayObjectAdapter(presenterSelector); mPlaybackControlsRow.setPrimaryActionsAdapter(mPrimaryActionsAdapter); mPlayPauseAction = new PlayPauseAction(getActivity()); mSkipNextAction = new PlaybackControlsRow.SkipNextAction(getActivity()); mSkipPreviousAction = new PlaybackControlsRow.SkipPreviousAction(getActivity()); mPrimaryActionsAdapter.add(mSkipPreviousAction); mPrimaryActionsAdapter.add(mPlayPauseAction); mPrimaryActionsAdapter.add(mSkipNextAction); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); youtubeTvView = (YoutubeTvView) getActivity().findViewById(R.id.youtubetv_view); youtubeTvView.updateView(getArguments()); youtubeTvView.playVideo(getArguments().getString("videoId", "")); mGlue = new VideoMediaPlayerGlue(getActivity(), this, youtubeTvView) { @Override protected void onRowChanged(PlaybackControlsRow row) { if (mRowsAdapter == null) return; mRowsAdapter.notifyArrayItemRangeChanged(0, 1); } }; mGlue.setOnMediaFileFinishedPlayingListener(this); mGlue.prepareMediaForPlaying(); setBackgroundType(PlaybackOverlayFragment.BG_LIGHT); addPlaybackControlsRow(); }
private void addPlaybackControlsRow(MediaMetadataCompat metadata) { mPlaybackControlsRow = new PlaybackControlsRow(new MutableMediaMetadataHolder(metadata)); mRowsAdapter.add(mPlaybackControlsRow); resetPlaybackRow(); ControlButtonPresenterSelector presenterSelector = new ControlButtonPresenterSelector(); mPrimaryActionsAdapter = new ArrayObjectAdapter(presenterSelector); mPlaybackControlsRow.setPrimaryActionsAdapter(mPrimaryActionsAdapter); mPlayPauseAction = new PlayPauseAction(getActivity()); mSkipNextAction = new PlaybackControlsRow.SkipNextAction(getActivity()); mSkipPreviousAction = new PlaybackControlsRow.SkipPreviousAction(getActivity()); mPrimaryActionsAdapter.add(mSkipPreviousAction); mPrimaryActionsAdapter.add(mPlayPauseAction); mPrimaryActionsAdapter.add(mSkipNextAction); }
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); }
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()); } }
@Override public void onActionClicked(Action action) { if (action == mPlayPauseAction) { mPlayPauseAction.nextIndex(); if (mPlayer != null) { mPlayer.setPlayWhenReady(mPlayPauseAction.getIndex() == PlaybackControlsRow.PlayPauseAction.PAUSE); } mGlue.notifyPlaybackRowChanged(); } }
@TargetApi(Build.VERSION_CODES.N) public void dispatchAction(Action action) { if (action instanceof PlaybackControlsRow.MultiAction) { PlaybackControlsRow.MultiAction multiAction = (PlaybackControlsRow.MultiAction) action; multiAction.nextIndex(); notifyActionChanged(multiAction); } if (action == mFastForwardAction) { mTransportControls.fastForward(); } else if (action == mRewindAction) { mTransportControls.rewind(); } else { super.onActionClicked(action); } }
private void notifyActionChanged(PlaybackControlsRow.MultiAction multiAction) { int index; index = getPrimaryActionsAdapter().indexOf(multiAction); if (index >= 0) { getPrimaryActionsAdapter().notifyArrayItemRangeChanged(index, 1); } else { index = getSecondaryActionsAdapter().indexOf(multiAction); if (index >= 0) { getSecondaryActionsAdapter().notifyArrayItemRangeChanged(index, 1); } } }
public PlaybackControlHelper(Context context, PlaybackOverlayFragment fragment, Video video) { super(context, fragment, SEEK_SPEEDS); mFragment = fragment; mVideo = video; mMediaController = mFragment.getActivity().getMediaController(); mTransportControls = mMediaController.getTransportControls(); 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); }
@Override public PlaybackControlsRowPresenter createControlsRowAndPresenter() { PlaybackControlsRowPresenter presenter = super.createControlsRowAndPresenter(); ArrayObjectAdapter adapter = new ArrayObjectAdapter(new ControlButtonPresenterSelector()); getControlsRow().setSecondaryActionsAdapter(adapter); mFastForwardAction = (PlaybackControlsRow.FastForwardAction) getPrimaryActionsAdapter() .lookup(ACTION_FAST_FORWARD); mRewindAction = (PlaybackControlsRow.RewindAction) getPrimaryActionsAdapter() .lookup(ACTION_REWIND); // odebrani zbytecnych tlacitek /* adapter.add(mThumbsDownAction); adapter.add(mRepeatAction); adapter.add(mThumbsUpAction); */ if (PlaybackOverlayActivity.supportsPictureInPicture(getContext())) { adapter.add(mPipAction); } presenter.setOnActionClickedListener(new OnActionClickedListener() { @Override public void onActionClicked(Action action) { dispatchAction(action); } }); return presenter; }
private void notifyActionChanged(PlaybackControlsRow.MultiAction action) { int index; index = getPrimaryActionsAdapter().indexOf(action); if (index >= 0) { getPrimaryActionsAdapter().notifyArrayItemRangeChanged(index, 1); } else { index = getSecondaryActionsAdapter().indexOf(action); if (index >= 0) { getSecondaryActionsAdapter().notifyArrayItemRangeChanged(index, 1); } } }
@Override public void onStart() { super.onStart(); // Set up UI Video video = getActivity().getIntent().getParcelableExtra(VideoDetailsActivity.VIDEO); if (!updateSelectedVideo(video)) { return; } mGlue = new PlaybackControlHelper(getActivity(), this, mSelectedVideo); PlaybackControlsRowPresenter controlsRowPresenter = mGlue.createControlsRowAndPresenter(); PlaybackControlsRow controlsRow = mGlue.getControlsRow(); mMediaControllerCallback = mGlue.createMediaControllerCallback(); mMediaController = getActivity().getMediaController(); mMediaController.registerCallback(mMediaControllerCallback); ClassPresenterSelector ps = new ClassPresenterSelector(); ps.addClassPresenter(PlaybackControlsRow.class, controlsRowPresenter); ps.addClassPresenter(ListRow.class, new ListRowPresenter()); mRowsAdapter = new ArrayObjectAdapter(ps); mRowsAdapter.add(controlsRow); addOtherRows(); updatePlaybackRow(); setAdapter(mRowsAdapter); startPlaying(); }
@Override public PlaybackControlsRowPresenter createControlsRowAndPresenter() { PlaybackControlsRowPresenter presenter = super.createControlsRowAndPresenter(); ArrayObjectAdapter adapter = new ArrayObjectAdapter(new ControlButtonPresenterSelector()); getControlsRow().setSecondaryActionsAdapter(adapter); mFastForwardAction = (PlaybackControlsRow.FastForwardAction) getPrimaryActionsAdapter() .lookup(ACTION_FAST_FORWARD); mRewindAction = (PlaybackControlsRow.RewindAction) getPrimaryActionsAdapter() .lookup(ACTION_REWIND); adapter.add(mThumbsDownAction); adapter.add(mRepeatAction); adapter.add(mThumbsUpAction); if (PlaybackOverlayActivity.supportsPictureInPicture(getContext())) { adapter.add(mPipAction); } presenter.setOnActionClickedListener(new OnActionClickedListener() { @Override public void onActionClicked(Action action) { dispatchAction(action); } }); return presenter; }
@Override public void onStart() { super.onStart(); // Set up UI Video video = getActivity().getIntent().getParcelableExtra(VideoDetailsActivity.VIDEO); if (!updateSelectedVideo(video)) { return; } mGlue = new PlaybackControlHelper(getActivity(), this, mSelectedVideo); PlaybackControlsRowPresenter controlsRowPresenter = mGlue.createControlsRowAndPresenter(); PlaybackControlsRow controlsRow = mGlue.getControlsRow(); mMediaControllerCallback = mGlue.createMediaControllerCallback(); // mMediaController = getActivity().getMediaController(); mMediaController.registerCallback(mMediaControllerCallback); // ClassPresenterSelector ps = new ClassPresenterSelector(); ps.addClassPresenter(PlaybackControlsRow.class, controlsRowPresenter); ps.addClassPresenter(ListRow.class, new ListRowPresenter()); mRowsAdapter = new ArrayObjectAdapter(ps); mRowsAdapter.add(controlsRow); addOtherRows(); updatePlaybackRow(); setAdapter(mRowsAdapter); startPlaying(); }
public PrimaryPlaybackControlsGlue( Context context, T adapter, MediaControllerCompat mediaController) { super(context, adapter); mMediaSessionTransportControls = mediaController.getTransportControls(); mSkipPreviousAction = new PlaybackControlsRow.SkipPreviousAction(context); mSkipNextAction = new PlaybackControlsRow.SkipNextAction(context); mFastForwardAction = new PlaybackControlsRow.FastForwardAction(context); mRewindAction = new PlaybackControlsRow.RewindAction(context); }
private void setUpRows() { PlaybackControlsRowPresenter controlsRowPresenter = mPlaybackControlHelper.createControlsRowAndPresenter(); ClassPresenterSelector selector = new ClassPresenterSelector(); selector.addClassPresenter(PlaybackControlsRow.class, controlsRowPresenter); selector.addClassPresenter(ListRow.class, new ListRowPresenter()); mRowsAdapter = new ArrayObjectAdapter(selector); mRowsAdapter.add(mPlaybackControlHelper.getControlsRow()); mRelatedRecordingsRow = getRelatedRecordingsRow(); setAdapter(mRowsAdapter); }
private void initialisePlaybackControlPresenter() { ClassPresenterSelector presenterSelector = new ClassPresenterSelector(); mPlaybackControlsRowPresenter = new PlaybackControlsRowPresenter(new DescriptionPresenter()); mPlaybackControlsRowPresenter.setSecondaryActionsHidden(false); presenterSelector.addClassPresenter(PlaybackControlsRow.class, mPlaybackControlsRowPresenter); presenterSelector.addClassPresenter(ListRow.class, new ListRowPresenter()); mRowsAdapter = new ArrayObjectAdapter(presenterSelector); setAdapter(mRowsAdapter); }
private void setupPlaybackControlItemsToReadyState() { mRowsAdapter.clear(); mPlaybackControlsRow = new PlaybackControlsRow(mStreamInfo); mPlaybackControlsRow.setCurrentTime(0); mPlaybackControlsRow.setBufferedProgress(0); ControlButtonPresenterSelector presenterSelector = new ControlButtonPresenterSelector(); setupPrimaryRowPlaybackControl(presenterSelector); setupSecondaryRowPlaybackControl(presenterSelector); mRowsAdapter.add(mPlaybackControlsRow); mRowsAdapter.notifyArrayItemRangeChanged(0, mRowsAdapter.size()); setupPlaybackControlItemsActions(); }
@Override protected void onCreatePrimaryActions(SparseArrayObjectAdapter primaryActionsAdapter) { this.primaryActionsAdapter = primaryActionsAdapter; closedCaptionAction = new PlaybackControlsRow.ClosedCaptioningAction(getContext()); closedCaptionAction.setIndex(PlaybackControlsRow.ClosedCaptioningAction.ON); primaryActionsAdapter.notifyArrayItemRangeChanged(primaryActionsAdapter.indexOf(closedCaptionAction), 1); primaryActionsAdapter.set(ACTION_CUSTOM_RIGHT_FIRST, closedCaptionAction); }
@Override public void onTrackSelectionsChanged(TrackSelections<? extends MappingTrackSelector.MappedTrackInfo> trackSelections) { int textRenderIndex = getRenderIndex(C.TRACK_TYPE_TEXT); boolean status = trackSelector.getRendererDisabled(textRenderIndex); closedCaptionAction.setIndex(status ? PlaybackControlsRow.ClosedCaptioningAction.ON : PlaybackControlsRow.ClosedCaptioningAction.OFF); primaryActionsAdapter.notifyArrayItemRangeChanged(primaryActionsAdapter.indexOf(closedCaptionAction), 1); }
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); }
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); } }
@Override protected void onPlayCompleted() { super.onPlayCompleted(); mHandler.post(new Runnable() { @Override public void run() { if (mRepeatAction.getIndex() != PlaybackControlsRow.RepeatAction.NONE) { play(); } } }); }
@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)); } } }
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; } }
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; } }