'Youtube Player error UNAUTHORIZED_OVERLAY

I'm working on youtube player api where I need to play youtube player view in PIP. this is my xml layout

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".activity.PictureInPicture">

        <com.google.android.youtube.player.YouTubePlayerView
            android:id="@+id/youtubePlayer"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </LinearLayout>

I'm playing video when mode is changed

override fun onPictureInPictureModeChanged(
        isInPictureInPictureMode: Boolean,
        newConfig: Configuration?
    ) {
        super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig)
        pipMode = isInPictureInPictureMode
        if (isInPictureInPictureMode) {
            if (youTubePlayer != null)
                youTubePlayer!!.play()
        } else {
            youTubePlayer!!.play()
        }

    }

but player stops with error message of UNAUTHORIZED_OVERLAY. Kindly guide me how to deal with it



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source