2015-08-08 39 views
0

當YouTube播放器片段嵌套在滾動型我得到的錯誤,當旋轉裝置景觀:YouTube播放器,滾動型機器人

YouTubePlayer.ErrorReason.UNAUTHORIZED_OVERLAY 

什麼是更有趣的是,當我刪除的問題消失滾動型 !但我可以

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
    > 
     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"/> 
     /> 
     <fragment 
      android:name="com.google.android.youtube.player.YouTubePlayerFragment" 
      android:id="@+id/youtubeplayerfragment" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"/> 
    </LinearLayout> 
</ScrollView> 
+0

scrollview應該只有一個孩子 –

回答

0

YouTubePlayer.ErrorReason.UNAUTHORIZED_OVERLAY錯誤指示*播放已停止由於覆蓋在播放機的視圖。這意味着YouTube播放器已被其他一些視圖所掩蓋。 YouTube API可以檢測到它並停止播放。

發生這種情況的一個常見原因是,用於保存YouTube播放器的片段嵌入滾動視圖中。滾動視圖添加了可以滾動的元素的附加層。對於你的情況。包含在同一聲明中的播放器將檢測到重疊,並最終停止提供上述錯誤。

0

我有同樣的問題與滾動型的內部YoutubePlayer並將其與此消息中止:

W/YouTubeAndroidPlayerAPI: YouTube video playback stopped due to unauthorized overlay on top of player. The YouTubePlayerView is not contained inside its ancestor android.widget.ScrollView{69b88e5 VFED.V... ........ 0,0-1794,1017 #7f0d0070 app:id/scrollview}. The distances between the ancestor's edges and that of the YouTubePlayerView is: left: 21, top: 196, right: 21, bottom: -164 (these should all be positive). 

這種情況發生時的視頻在屏幕上不完全可見的所有時光。當它完全可見時,旋轉設備工作正常。對我來說,這看起來像Youtube Android播放器中的一個錯誤。我做了下面的代碼解決方法:

@Override 
public void onConfigurationChanged(Configuration newConfig) { 
    super.onConfigurationChanged(newConfig); 

    // This is an ugly workaround to prevent youtube from (wrongly) thinking we have an 
    // overlay above the video. Having overlays is not allowed and the video would stop otherwise. 
    DisplayMetrics metrics = getResources().getDisplayMetrics(); 
    int offset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 25, metrics); 
    scrollView.scrollTo(0, youtubePlayer.getView().getTop() - offset); 
} 

這顯然不是一個很好的修復,因爲它取決於視頻的比率,它是如何顯示您的顯示器上。此外,您的ScrollView將在旋轉後滾動到不同的位置(您可以稍後重新手動重新設置)。