Android YouTubePlayer with unauthorized overlay on top of player

筅森魡賤 提交于 2019-11-27 05:16:08

Were you able to solve this problem?

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" />
lucasddaniel

The problem is only with layout, the YouTube Player doesn't permit any view staying over it, neither invisible nor transparent.

In order to make this visible in your device, enable layout bounds in developer option.(warning with paddings and margins)

Try to comment out others views' code on your layout and test this again please.

I had the same error. Although I did the XML changes, I continued to receive the error:

 YouTube video playback stopped due to unauthorized overlay on top of player. The YouTubePlayerView is obscured by android.view.View{59fa6ce V.ED..... ........ 0,0-1440,84 #102002f android:id/statusBarBackground}. The view is inside the YouTubePlayerView, with the distance in px between each edge of the obscuring view and the YouTubePlayerView being: left: 0, top: 0, right: 0, bottom: 2308..

After I set the FULLSCREEN, it worked perfect

getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

Hope it will help others.

The demo code for the Android API uses this layout for the Fragment demo, maybe that can get ideas going. See this page: https://developers.google.com/youtube/android/player/

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

  <TextView
      android:layout_width="match_parent"
      android:layout_height="0dp"
      android:layout_weight="1"
      android:textAppearance="@android:style/TextAppearance.Small"
      android:gravity="center"
      android:text="@string/playerfragment_text"/>

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

Youtube Player find out some views overlay it. Just remove those view or setVisible(View.GONE) for them. Please check this link for more information Solution

Shiva

You have to remove any padding attribute in the Video view.

Wrong:

   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:orientation="vertical" >

   <com.google.android.youtube.player.YouTubePlayerView
    android:id="@+id/youtube_player"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    **android:padding="10dp"** />

    </LinearLayout>

Right:

   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

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

    </LinearLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:id="@+id/id_base_layout"
android:fitsSystemWindows="true"
android:layout_height="match_parent"
android:background="#000000">

<com.google.android.youtube.player.YouTubePlayerView
    android:id="@+id/youtube_view"
    android:layout_width="match_parent"
    android:layout_centerInParent="true"
    android:layout_height="wrap_content"  />

1.add fitSystemWindows. 2.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!