【发布时间】:2019-02-22 13:25:48
【问题描述】:
我正在尝试在 Fragment 中使用 recyclerview 设置 Youtube 视频列表。 我在那个活动中有一个活动,一个片段在那里管理底部导航选择,另一个片段用于管理选项卡选择的 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).
【问题讨论】:
-
这个错误通常是由他们的 API 引发的。长话短说,你不必用任何东西覆盖视频。根据您的 xml,我猜布局底部的一个/两个
TextViews 可能会覆盖播放器..先检查一下。我找到了this 可能对您有所帮助的示例 -
我删除了那些
TextViews 但没有解决我的问题 -
看看我编辑的评论。那个 git 样本
-
我已经看到了这个示例,我正在从相同的示例中获取示例,但无法正常工作
-
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).您要在屏幕上播放的视频还是什么?看起来它在recyclerview的可见部分下方滚动。另外,您的 XML 中的YoutubePlayerView在哪里?
标签: android android-fragments youtube-api android-youtube-api