Android YouTubePlayer 在播放器顶部带有未经授权的覆盖

标签 android youtube-api android-framelayout

我在 Fragment 中使用 YouTubePlayer(Android 版 YouTube api) 我用 YouTube 播放器给 LinearLayout 充气,用这种方式:

fragmentManager = getActivity().getSupportFragmentManager();
                    fragmentTransaction = fragmentManager.beginTransaction();

                    player = new YouTubePlayerSupportFragment();
                    fragmentTransaction.add(R.id.youTubePlayerContainer, player); 
                    fragmentTransaction.commit();

...youTubePlayerContainer 是膨胀的 LinearLayout

正确检测到播放器,开始播放,然后停止。 日志显示如下:

YouTube video playback stopped due to unauthorized overlay on top of player. 
The YouTubePlayerView is obscured by android.widget.FrameLayout@4110d1f8. 
YouTubePlayerView is completely covered, with the distance in px between each edge of the obscuring view and the YouTubePlayerView being: left: 484, top: 100, right: 100, bottom: 170..

这是我的 XML: (里面没有FrameLayout)

 <LinearLayout
        android:id="@+id/curtain"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <LinearLayout
            android:id="@+id/withApi"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <LinearLayout
                android:id="@+id/youTubePlayerContainer"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_gravity="center"
                android:layout_margin="30dp"
                android:layout_weight="1"
                android:orientation="vertical" >
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="3dp"
                android:background="@color/trans_popUp"
                android:padding="3dp" >

                <TextView
                    android:id="@+id/textYouTubeVisor"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Title..."
                    android:textColor="@color/white" />
            </LinearLayout>
        </LinearLayout>

我尝试更改页边距但没有成功。 我阅读了官方文档但没有成功 表示导致问题的FrameLayout为:android.widget.FrameLayout@4110d1f8 但是有了这样的引用并不能确定是哪个引用

对他做过这件事的人?

感谢您的帮助。

问候

最佳答案

我今天遇到了同样的问题,对我来说,日志中的错误是:

W/YouTubeAndroidPlayerAPI﹕ YouTube video playback stopped due to unauthorized overlay on top of player. The YouTubePlayerView is not contained inside its ancestor com.google.android.youtube.player.YouTubePlayerView{42686bc8 V.E..... ........ 0,0-1200,675 #7f0a00a0 app:id/video_player}. The distances between the ancestor's edges and that of the YouTubePlayerView is: left: -10, top: -10, right: -10, bottom: -10 (these should all be positive).

我通过删除布局中 YouTubePlayerView 中的填充来解决此问题。所以我的布局是这样的:

<com.google.android.youtube.player.YouTubePlayerView
    android:id="@+id/video_player"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#000" />

关于Android YouTubePlayer 在播放器顶部带有未经授权的覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16067783/

相关文章:

java - 如何从服务中打开(切换、设置)软键盘

android - FFmpeg Android 连接。 "–safe 0"是无效参数

youtube - 无需任何身份验证即可在youtube上检索用户上传的视频

android - FrameLayout subview 在调整大小时未正确更新

android - 不需要的 FrameLayout 拉伸(stretch)以包裹所有 child 的高度(而不是只考虑一个 child 的高度)

android - 从 RecyclerView 中删除行

java - 计算器应用程序的定制键盘

javascript - 如何获得Youtube直播位置?

php - 如何使用 youtube api v3 获取 youtube 视频的完整描述

android - 将 View 向下推到屏幕的布局