androidx.leanback.media.PlaybackTransportControlGlue Java Examples
The following examples show how to use
androidx.leanback.media.PlaybackTransportControlGlue.
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: VodPlaybackFragment.java From xipl with Apache License 2.0 | 5 votes |
/** * Sets up the usage of the internal player used by the library. */ protected void configureInternalPlayer() { Bundle arguments = getArguments(); String url = arguments.getString(VodTvSectionFragment.AV_CONTENT_LINK_BUNDLE); // Configure the ExoPlayer instance that will be used to play the media DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(getActivity(), Util.getUserAgent(getActivity(), getActivity().getApplicationInfo().loadLabel(getActivity().getPackageManager()).toString())); mSimpleExoPlayer = ExoPlayerFactory.newSimpleInstance(new DefaultRenderersFactory(getActivity()), new DefaultTrackSelector(), new DefaultLoadControl()); ExtractorMediaSource.Factory factory = new ExtractorMediaSource.Factory(dataSourceFactory); Uri uri = Uri.parse(url); mSimpleExoPlayer.prepare(factory.createMediaSource(uri)); mSimpleExoPlayer.addListener(new Player.DefaultEventListener() { @Override public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { super.onPlayerStateChanged(playWhenReady, playbackState); if (playbackState == Player.STATE_READY && mPlayerGlue.getSeekProvider() == null) { mPlayerGlue.setSeekProvider(new ProviderPlaybackSeekDataProvider(mPlayerGlue.getDuration())); // Force content to fit to screen if wanted. if (getVodProperties().isVideoFitToScreen()) { DisplayMetrics displayMetrics = getActivity().getResources().getDisplayMetrics(); mPlayerGlue.getPlayerAdapter().getCallback().onVideoSizeChanged(mPlayerGlue.getPlayerAdapter(), displayMetrics.widthPixels, displayMetrics.heightPixels); } } } }); // Configure Leanback for playback. Use the updatePeriodMs used before in ExoPlayerAdapter LeanbackPlayerAdapter playerAdapter = new LeanbackPlayerAdapter(getActivity(), mSimpleExoPlayer, 16); mPlayerGlue = new PlaybackTransportControlGlue<>(getActivity(), playerAdapter); mPlayerGlue.setHost(new VideoSupportFragmentGlueHost(this)); mPlayerGlue.setTitle(arguments.getString(VodTvSectionFragment.AV_CONTENT_TITLE_BUNDLE)); mPlayerGlue.setSubtitle(arguments.getString(VodTvSectionFragment.AV_CONTENT_GROUP_BUNDLE)); setBackgroundType(BG_LIGHT); mPlayerGlue.playWhenPrepared(); }