Search code examples
androidandroid-fragmentsyoutube-apiandroid-youtube-api

Problem about YouTubePlayer API for an application within a nested Fragment


I'm trying to setup Youtube video list using recyclerview within Fragment. I have an activity in that activity a fragment is there which manages bottom navigation selection another fragment is for tablayout which manages tab selection and final is the adapter in which I have my recyclerview which is setting up video list Everything is working as I planned but when I play video it YoutubePlayerAPI pause the video. I tried fix this by searching on Google but not able fix.

below is my video_recycler_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:fresco="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:elevation="4dp"
    android:background="@android:color/white"
    android:clipToPadding="false"
    android:layout_marginLeft="4dp"
    android:layout_marginRight="4dp"
    android:padding="4dp"
    android:orientation="vertical">
    <RelativeLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <com.facebook.drawee.view.SimpleDraweeView
            android:id="@+id/ivFeedCenter"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            fresco:placeholderImage="@color/colorPrimary"/>
        <View
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#4f000000"/>
        <ImageView
            android:id="@+id/play_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:src="@drawable/ic_video_play"/>

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/video_container"
            android:tag="@string/video_component_tag">

        </FrameLayout>
    </RelativeLayout>
    <TextView
        android:id="@+id/title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textStyle="bold"
        android:textSize="20sp"/>
    <TextView
        android:id="@+id/description"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
</LinearLayout>

Can any one tell what I am doing wrong in it?

I am getting message in logcat which I have mentioned below

W/YouTubeAndroidPlayerAPI: YouTube video playback stopped due to unauthorized overlay on top of player. The YouTubePlayerView is not contained inside its ancestor android.support.v7.widget.RecyclerView{f61352e VFED..... ........ 0,0-1080,1560 #7f0a01df app:id/rvFeed}. The distances between the ancestor's edges and that of the YouTubePlayerView is: left: 24, top: 1402, right: 24, bottom: -422 (these should all be positive).

Solution

  • to avoid the pause, you need to hidden all views that overlay your framelayout, because I see that your frame is match_parent. When you do click in play video hide everything and try. Also look if you don´t have an FloatingActionButton or other view overlay.