YouTubePlayerFragment:YouTube视频播放因播放器顶部未经授权的覆盖而停止

时间:2016-04-10 06:53:57

标签: android video youtube youtube-api

我正在尝试使用YouTube API在viewpager中播放YouTube视频。我的片段由一个FrameLayout组成,我在其中播放视频。视频正在加载,但一旦播放就停止播放。 错误日志显示为:

W/YouTubeAndroidPlayerAPI: YouTube video playback stopped due to unauthorized overlay on top of player. The YouTubePlayerView is obscured by android.widget.LinearLayout{ffe4270 V........ ........ 5425,0-6505,1437 #7f0e00cd app:id/root}. YouTubePlayerView is completely covered, with the distance in px between each edge of the obscuring view and the YouTubePlayerView being: left: 0, top: 0, right: 0, bottom: 830..
W/YouTubeAndroidPlayerAPI: 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{d17b08c VFED..... ......I. 0,210-1080,1794 #7f0e0089 app:id/viewPager}. The distances between the ancestor's edges and that of the YouTubePlayerView is: left: 1085, top: 0, right: -1085, bottom: 830 (these should all be positive).

我无法弄清楚问题,因为没有视图遮挡了框架布局。 布局文件是:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<!-- Youtube fragment -->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/youtube_fragment"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:visibility="visible" />
<!--android:name="com.google.android.youtube.player.YouTubePlayerFragment"-->
</linearLayout>

如果删除外部布局并仅播放framelayout,它仍然会出现错误。

1 个答案:

答案 0 :(得分:-1)

在Android中,当您使用YouTube API时,视频必须位于屏幕顶部,您既不使用 public static void PrintCounters(IEnumerable<Counter> counters) { foreach (Counter c in counters) { Console.WriteLine("{0} is {1}", c.Name, c.Address); } } 也不使用YoutubePlayerFragment。如果不是,则会引发像您这样的错误。

使用这段代码我不能那么具体,但我想有一个覆盖你YoutubePlayerActivity的布局,这是因为你看错了。

希望它可以帮到你,