0

I am trying to add youtube player as popup inside double viewpager, but the player stops giving following errors alternatively:

YouTube video playback stopped due to unauthorized overlay on top of player. The YouTubePlayerView is not contained inside its ancestor android.support.v4.view.ViewPager{344132a VFED..... ........ 0,144-1080,1560 #7f0e00a1 app:id/pager_video}. The distances between the ancestor's edges and that of the YouTubePlayerView is: left: 1080, top: 809, right: -1080, bottom: 0 (these should all be positive).

and

YouTube video playback stopped because the player's view is not visible. The view android.widget.LinearLayout{36c8aa6 I.E...... ......ID 0,653-1080,1416 #7f0e009a app:id/video_box} has visibility "INVISIBLE".

I have three xml files:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.example.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.design.widget.TabLayout
        android:id="@+id/sliding_tabs"
        style="@style/customTabLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        android:elevation="@dimen/tiny_dimen" />

</android.support.design.widget.AppBarLayout>

<android.support.v4.view.ViewPager
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

B.xml

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

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.design.widget.TabLayout
            android:id="@+id/sliding_tabs_video"
            style="@style/customTabLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorPrimary"
            android:elevation="@dimen/tiny_dimen" />
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/pager_video"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</LinearLayout>

C.xml

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

<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/swipeToRefreshLayoutVideo"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <SearchView
            android:id="@+id/videoSearch"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:visibility="gone"/>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view_video_list"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:clipToPadding="false"
            android:scrollbars="vertical" />
    </LinearLayout>
</android.support.v4.widget.SwipeRefreshLayout>

<LinearLayout
    android:id="@+id/video_box"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:orientation="vertical"
    android:visibility="visible">

    <ImageButton
        android:id="@+id/close_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:onClick="onClickClose"
        android:src="@android:drawable/btn_dialog" />

    <fragment
        android:id="@+id/video_fragment_container"
        android:name="com.example.fragments.VideoFragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    </LinearLayout>
</FrameLayout>

When I put C inside A, it works perfectly but when I put C inside B which is inside A, it gives errors.

P.S. Here youtube com.example.fragments.VideoFragment is YouTubePlayerSupportFragment

bpsingh
  • 363
  • 1
  • 4
  • 18

1 Answers1

0

Based from this thread, the error happened when scrolling the page, on which the YouTubePlayerView is located. When the YouTubePlayerView becomes invisible the video stopped with this error.

Overlays on top of any of YouTube players (including the YouTube Android Player) are not supported. When an overlay is detected, playback stops and the log contains information helpful in debugging the issue.

abielita
  • 13,147
  • 2
  • 17
  • 59