18

I'm using YouTubePlayer (YouTube api for android) within a Fragment I am inflating a LinearLayout with the YouTube Player, in this way:

fragmentManager = getActivity().getSupportFragmentManager();
                    fragmentTransaction = fragmentManager.beginTransaction();

                    player = new YouTubePlayerSupportFragment();
                    fragmentTransaction.add(R.id.youTubePlayerContainer, player); 
                    fragmentTransaction.commit();

...Where youTubePlayerContainer is the inflated LinearLayout

The player is detected correctly, start playing and in a second stops. The Log shows the following:

YouTube video playback stopped due to unauthorized overlay on top of player. 
The YouTubePlayerView is obscured by android.widget.FrameLayout@4110d1f8. 
YouTubePlayerView is completely covered, with the distance in px between each edge of the obscuring view and the YouTubePlayerView being: left: 484, top: 100, right: 100, bottom: 170..

This is my XML: (No FrameLayout within it)

 <LinearLayout
        android:id="@+id/curtain"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <LinearLayout
            android:id="@+id/withApi"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <LinearLayout
                android:id="@+id/youTubePlayerContainer"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_gravity="center"
                android:layout_margin="30dp"
                android:layout_weight="1"
                android:orientation="vertical" >
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="3dp"
                android:background="@color/trans_popUp"
                android:padding="3dp" >

                <TextView
                    android:id="@+id/textYouTubeVisor"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Title..."
                    android:textColor="@color/white" />
            </LinearLayout>
        </LinearLayout>

I tried changing the margins without success. I read the official documentation but without success Indicates that the FrameLayout that causes the problem is: android.widget.FrameLayout @ 4110d1f8 But with such a reference does not identify which refers

to someone he did this happen?

I appreciate any help.

Regards

Sergio76
  • 3,835
  • 16
  • 61
  • 88

8 Answers8

19

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" />
Dharman
  • 30,962
  • 25
  • 85
  • 135
Bonton255
  • 2,231
  • 3
  • 28
  • 44
  • 1
    Helped me as well. Additional info- the error happened also when scrolling the page, on which the YouTubePlayerView is located. When the YouTubePlayerView becomes invisible (in mt case due to scroll on activity), the video stopped with this error – user2924714 Apr 27 '16 at 11:47
  • 1
    Am using frame layout instead of youtube player. Its not working for me – syedjibharat Mar 20 '18 at 13:44
  • for signed apk its working without made any changes – varotariya vajsi Jan 22 '20 at 16:07
7

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.

Igor Fridman
  • 1,267
  • 1
  • 16
  • 30
5

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.

Mahedi Hassan
  • 93
  • 1
  • 10
lucasddaniel
  • 1,779
  • 22
  • 22
2

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>
2

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

Community
  • 1
  • 1
BaDo
  • 540
  • 8
  • 19
1

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>
Tim
  • 41,901
  • 18
  • 127
  • 145
Shiva
  • 11
  • 1
0
<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);

HongSec Park
  • 1,193
  • 8
  • 9
0

I faced the same problem while play video in youtubeplayer

when I Add this line ...It's Work for me

getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
Martin
  • 2,411
  • 11
  • 28
  • 30
jyoti solanki
  • 49
  • 1
  • 1
  • 4