Android Youtubeplayer with Unauthorized Overlay on Top of Player

Android YouTubePlayer with unauthorized overlay on top of player

I faced the same problem today, and for me the error in the logs was:

W/YouTubeAndroidPlayerAPI﹕ YouTube video playback stopped due to unauthorized overlay on top of player. The YouTubePlayerView is not contained inside its ancestor com.google.android.youtube.player.YouTubePlayerView{42686bc8 V.E..... ........ 0,0-1200,675 #7f0a00a0 app:id/video_player}. The distances between the ancestor's edges and that of the YouTubePlayerView is: left: -10, top: -10, right: -10, bottom: -10 (these should all be positive).

I fixed this by removing the padding in the YouTubePlayerView in the layout. So my layout looks like this:

<com.google.android.youtube.player.YouTubePlayerView
android:id="@+id/video_player"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#000" />

Error on YTBPlayer: YouTube video playback stopped due to unauthorized overlay on top of player

  1. It is possible to solve that error: you can't have any View overlaying Google's YouTube Player. The only way to use Google's library is to make sure that their constraints are satisfied.
  2. Google's YouTube Player API is not open source, there's no way for you to change its behavior.
  3. Yes, Android-YouTube-Player. This library automatically solves both problems. You can overlay whatever you want to the player and, if you need to, you can customize the code, being it an open source project. Also the library do not requires the users to have the official YouTube app installed on the phone, and gives you freedom on how you want to customize the UI of the player.

Video pausing with error Unauthorized overlay

Taken from the documentation

FULLSCREEN_FLAG_CUSTOM_LAYOUT disables the default fullscreen layout handler, enabling you to control the transition to fullscreen layout manually.

As you see, setting that flag leaves to you the task of handling the UI elements' visibility, in particular those belonging to the System UI (status bar, navigation bar).

For this reason, if you fail to hide the status bar, the YouTube player will detect that a view is being displayed over it and will therefore throw that warning.


You can try with one of the following additional flags

FULLSCREEN_FLAG_ALWAYS_FULLSCREEN_IN_LANDSCAPE: causes the player to automatically enter fullscreen whenever the device enters landscape orientation.

FULLSCREEN_FLAG_CONTROL_ORIENTATION: enables automatic control of the orientation.

FULLSCREEN_FLAG_CONTROL_SYSTEM_UI: enables automatic control of system UI.

FULLSCREEN_FLAG_CUSTOM_LAYOUT: disables the default fullscreen layout handler, enabling you to control the transition to fullscreen layout manually.

or, if you actually need to have manual control over the System UI, keep using the custom layout flag and be sure to handle the UI elements' visibility.



Related Topics



Leave a reply



Submit