Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show/Hide subtitle in YouTubePlayer #377

Open
zjamshidi opened this issue Oct 25, 2019 · 1 comment
Open

Show/Hide subtitle in YouTubePlayer #377

zjamshidi opened this issue Oct 25, 2019 · 1 comment

Comments

@zjamshidi
Copy link

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);
        }
    }
@wahdatkashmiri33
Copy link

wahdatkashmiri33 commented Jan 29, 2020

`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()

}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants