【问题标题】:Android YouTubePlayer with unauthorized overlay on top of playerAndroid YouTubePlayer 在播放器顶部带有未经授权的覆盖
【发布时间】:2013-04-10 16:08:21
【问题描述】:

我在 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 但是有了这样的引用并不能确定是哪个引用

对他做过这件事的人?

感谢您的帮助。

问候

【问题讨论】:

  • 播放器的设计使您不能在内容或控件上放置任何东西。由于您没有在布局中包含播放器,因此我只能假设布局出现在视频上方,而不是在视频下方。你能在游戏中看到你的标题吗?
  • 问题解决了吗?请告诉我,我被困在这里:(
  • @Reyjhon 我没有解决这个问题。如果我找到解决方案,我会解释。如果你找到一个,我会很感激你告诉我。问候
  • 你有没有找到任何解决方案,因为我也被困在这里:(
  • Its not working for debug apk but when i generated signed apk its 工作正常。

标签: android youtube-api android-framelayout


【解决方案1】:

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

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" />

【讨论】:

  • 这解决了我的问题,非常感谢您的分享!
  • 也帮助了我。附加信息 - 滚动 YouTubePlayerView 所在的页面时也会发生错误。当 YouTubePlayerView 变得不可见时(在 mt 情况下由于滚动活动),视频因此错误而停止
  • 我正在使用框架布局而不是 youtube 播放器。它不适合我
  • 对于已签名的 apk,无需进行任何更改即可工作
【解决方案2】:

我有同样的错误。 虽然我做了 XML 更改,但我仍然收到错误:

 YouTube video playback stopped due to unauthorized overlay on top of player. The YouTubePlayerView is obscured by android.view.View{59fa6ce V.ED..... ........ 0,0-1440,84 #102002f android:id/statusBarBackground}. The view is inside the YouTubePlayerView, with the distance in px between each edge of the obscuring view and the YouTubePlayerView being: left: 0, top: 0, right: 0, bottom: 2308..

设置全屏后,效果完美

getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

希望它能帮助其他人。

【讨论】:

  • 是的,有帮助! :) :D
【解决方案3】:

问题仅在于布局,YouTube Player 不允许任何视图停留在其上方,既不可见也不透明。

为了使其在您的设备中可见,请在开发者选项中启用布局边界。(警告 paddingsmargins

请尝试在您的布局上注释掉其他视图的代码并再次测试。

【讨论】:

    【解决方案4】:

    Android API 的演示代码在 Fragment 演示中使用了这种布局,也许这样可以 让想法继续下去。看到这个页面:https://developers.google.com/youtube/android/player/

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    
      <TextView
          android:layout_width="match_parent"
          android:layout_height="0dp"
          android:layout_weight="1"
          android:textAppearance="@android:style/TextAppearance.Small"
          android:gravity="center"
          android:text="@string/playerfragment_text"/>
    
      <fragment
          android:name="com.google.android.youtube.player.YouTubePlayerFragment"
          android:id="@+id/youtube_fragment"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"/>
    </LinearLayout>
    

    【讨论】:

      【解决方案5】:

      Youtube Player 发现一些视图覆盖它。只需为它们删除那些视图或 setVisible(View.GONE) 即可。 请检查此链接以获取更多信息 Solution

      【讨论】:

        【解决方案6】:

        您必须删除视频视图中的任何填充属性。

        错误:

           <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
           xmlns:tools="http://schemas.android.com/tools"
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           android:orientation="vertical" >
        
           <com.google.android.youtube.player.YouTubePlayerView
            android:id="@+id/youtube_player"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            **android:padding="10dp"** />
        
            </LinearLayout>
        

        对:

           <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
           xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >
        
            <com.google.android.youtube.player.YouTubePlayerView
            android:id="@+id/youtube_player"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
             />
        
            </LinearLayout>
        

        【讨论】:

          【解决方案7】:
          <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:id="@+id/id_base_layout"
          android:fitsSystemWindows="true"
          android:layout_height="match_parent"
          android:background="#000000">
          
          <com.google.android.youtube.player.YouTubePlayerView
              android:id="@+id/youtube_view"
              android:layout_width="match_parent"
              android:layout_centerInParent="true"
              android:layout_height="wrap_content"  />
          

          1.添加fitSystemWindows。 2.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

          【讨论】:

            【解决方案8】:

            我在 youtubeplayer 中播放视频时遇到了同样的问题

            当我添加这一行时......它对我有用

            getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
            

            【讨论】:

              猜你喜欢
              • 2016-07-31
              • 2018-08-29
              • 1970-01-01
              • 2018-08-30
              • 2015-04-10
              • 2017-05-19
              • 2018-04-16
              • 1970-01-01
              • 2011-12-15
              相关资源
              最近更新 更多