Android YouTubePlayer pauses in PIP mode

270 Views Asked by At

I'm using YouTubePlayerFragment to play YouTube videos. When the activity goes to PIP mode the PLAYER_VIEW_TOO_SMALL error. Any idea how to fix it?

Layout

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

There is no padding.

Code:

        findViewById(R.id.pip_menu).setOnClickListener(view -> {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                enterPictureInPictureMode();
            }
        });
    ....
    @Override
    public void onPictureInPictureModeChanged (boolean isInPictureInPictureMode, Configuration newConfig) {
        if (isInPictureInPictureMode) {
            hideControllers();
            new Handler().postDelayed(() -> setPlayPause(true), 1000);
        } else {
            showControllers();
        }
    }

0

There are 0 best solutions below