关于嵌套片段中应用程序的 YouTubePlayer API 的问题

Problem about YouTubePlayer API for an application within a nested Fragment

我正在尝试使用 Fragment 中的 recyclerview 设置 Youtube 视频列表。 我有一个 activity,其中 activity 有一个片段管理底部导航选择,另一个片段用于 tablayout,它管理选项卡选择,最后是适配器,我有我的 recyclerview,它正在设置视频列表一切都按我的计划进行,但是当我播放视频时,YoutubePlayerAPI 会暂停视频。 我尝试通过搜索 Google 来修复此问题,但无法修复。

下面是我的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>

谁能告诉我我做错了什么?

我在下面提到的 logcat 中收到消息

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).

我想当你点击播放按钮时 framLayout 的高度是 0 dp 并且 youtubePlayer.init("somevideID") 会尝试播放视频但是因为高度是 0 dp 它只是插入视频并暂停视频。

事情是这样的:

**Insert video 
Play the Video 
Height is Zero at insertion time 
So it pauses the video instantly**

所以做一件事将高度 添加到 frameLayout 中,例如 200dp 并使其不可见。现在 before 调用 youtubePlayer.init() 使 frameLayout visible。然后 然后 调用 youtubePlayer.init()。这将解决您的问题。

为了避免停顿,您需要隐藏所有覆盖您的框架布局的视图,因为我看到您的框架是 match_parent。当您点击播放视频时,隐藏所有内容并尝试。还要查看您是否没有 FloatingActionButton 或其他视图覆盖。