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

问题描述 投票:0回答:2

我正在尝试使用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).
android android-fragments youtube-api android-youtube-api
2个回答
1
投票

为了避免暂停,你需要隐藏覆盖你的framelayout的所有视图,因为我看到你的框架是match_parent。当您点击播放视频时隐藏所有内容并尝试。另请查看您是否没有FloatingActionButton或其他视图叠加层。


0
投票

我认为当你点击播放按钮时,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**

所以有一件事就像200dp一样将高度添加到frameLayout并使其不可见。在调用youtubePlayer.init()之前,使frameLayout可见。然后调用youtubePlayer.init()。这将解决您的问题。

© www.soinside.com 2019 - 2024. All rights reserved.