androidx.leanback.app.VideoSupportFragmentGlueHost Java Examples

The following examples show how to use androidx.leanback.app.VideoSupportFragmentGlueHost. 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: PlaybackFragment.java    From tv-samples with Apache License 2.0 6 votes vote down vote up
private void initializePlayer() {
    BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
    TrackSelection.Factory videoTrackSelectionFactory =
            new AdaptiveTrackSelection.Factory(bandwidthMeter);
    mTrackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);

    mPlayer = ExoPlayerFactory.newSimpleInstance(getActivity(), mTrackSelector);
    mPlayerAdapter = new LeanbackPlayerAdapter(getActivity(), mPlayer, UPDATE_DELAY);
    mPlaylistActionListener = new PlaylistActionListener(mPlaylist);
    mPlayerGlue = new VideoPlayerGlue(getActivity(), mPlayerAdapter, mPlaylistActionListener);
    mPlayerGlue.setHost(new VideoSupportFragmentGlueHost(this));
    mPlayerGlue.playWhenPrepared();

    play(mVideo);

    ArrayObjectAdapter mRowsAdapter = initializeRelatedVideosRow();
    setAdapter(mRowsAdapter);
}
 
Example #2
Source File: PlaybackFragment.java    From androidtv-Leanback with Apache License 2.0 6 votes vote down vote up
private void initializePlayer() {
    BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
    TrackSelection.Factory videoTrackSelectionFactory =
            new AdaptiveTrackSelection.Factory(bandwidthMeter);
    mTrackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);

    mPlayer = ExoPlayerFactory.newSimpleInstance(getActivity(), mTrackSelector);
    mPlayerAdapter = new LeanbackPlayerAdapter(getActivity(), mPlayer, UPDATE_DELAY);
    mPlaylistActionListener = new PlaylistActionListener(mPlaylist);
    mPlayerGlue = new VideoPlayerGlue(getActivity(), mPlayerAdapter, mPlaylistActionListener);
    mPlayerGlue.setHost(new VideoSupportFragmentGlueHost(this));
    mPlayerGlue.playWhenPrepared();

    play(mVideo);

    ArrayObjectAdapter mRowsAdapter = initializeRelatedVideosRow();
    setAdapter(mRowsAdapter);
}
 
Example #3
Source File: VodPlaybackFragment.java    From xipl with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}