android_guides icon indicating copy to clipboard operation
android_guides copied to clipboard

Show/Hide subtitle in YouTubePlayer

Open zjamshidi opened this issue 6 years ago • 1 comments

I'm using a "YouTubePlayerFragment" in my android app. According to our requirements, I need to use "CHROMELESS" player style and use custom controllers. Is it any way to show/hide captions programmatically?

Layout

 <com.android.ui.widget.TouchEventLinearLayout
        android:id="@+id/youtubeFragmentLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true">

        <fragment
            android:id="@+id/youtubeFragment"
            android:name="com.google.android.youtube.player.YouTubePlayerFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </com.android.ui.widget.TouchEventLinearLayout>

Player Initialization:

@Override
    public void onInitializationSuccess(YouTubePlayer.Provider provider,
                                        YouTubePlayer player, boolean wasRestored) {
        youTubePlayer = player;
        youTubePlayer.setPlayerStyle(YouTubePlayer.PlayerStyle.CHROMELESS);
        youTubePlayer.setFullscreenControlFlags(YouTubePlayer.FULLSCREEN_FLAG_CONTROL_SYSTEM_UI);
        setPlayPause(isPlaying);
        initialProgressHandler();

        resumePoint = calculateResumePoint();
        if (!wasRestored) {
            if (isPlaying)
                youTubePlayer.loadVideo(mItem.getVideoId(), resumePoint);
            else
                youTubePlayer.cueVideo(mItem.getVideoId(), resumePoint);
        }
    }

zjamshidi avatar Oct 25 '19 12:10 zjamshidi

`private fun initPlayer() { trackSelector = DefaultTrackSelector() exoPlayer = ExoPlayerFactory.newSimpleInstance(context, trackSelector) concatingMediaSource= ConcatenatingMediaSource(getMediaSource(vods)) exoPlayer.prepare(concatingMediaSource) exoPlayer.currentWindowIndex

}

override fun captions(isCaptionOff: Boolean) {

        trackSelector.parameters = ParametersBuilder().setRendererDisabled(C.TRACK_TYPE_VIDEO,isCaptionOff).build()

}`

wahdatkashmiri33 avatar Jan 29 '20 12:01 wahdatkashmiri33