3

This is my main fragment

public class VirtualClassFragment extends Fragment// implements YouTubePlayer.OnInitializedListener 
{
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
     {
        View v = inflater.inflate(R.layout.fragment_virtual_class, container, false);
        YouTubePlayerSupportFragment pl = (YouTubePlayerSupportFragment) getChildFragmentManager().findFragmentById(R.id.youTubePlayerFragment);

        pl.initialize("<API_KEY>", new YouTubePlayer.OnInitializedListener() {
            @Override
            public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
                youTubePlayer.cueVideo("nGyqHoKa7yk");
            }

            @Override
            public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {

            }
        });
        return v;
     }
 }

and here is my xml file

<FrameLayout 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">


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

</FrameLayout>

I am getting youtube video, but after playing it for 1 second, it gives me error of "UNAUTHORIZED_OVERLAY".
I have searched a lot and everyone is saying we can not add another view on it, but as you can see there is just fragment in my xml, nothing else.

Ravi
  • 34,851
  • 21
  • 122
  • 183

2 Answers2

5

As of youtube api:

YouTubePlayer.ErrorReason.UNAUTHORIZED_OVERLAY: Playback has been stopped due to a view overlaying the player. Which can be found in here its might also happen by adding padding, margin or other views created by your activity..

I Can also suggest you creating fresh activity and fragment which contains only youtube view and testing it..

Also maby this links will help you understand more of this issue:

link1

link 2

Community
  • 1
  • 1
SacreDeveloper
  • 1,253
  • 1
  • 9
  • 16
0

This simply means that you have some view above your player. Remove this view and the error will be gone.

Barakuda
  • 790
  • 8
  • 16