我在我的应用中使用Youtube Api for Android,我在我的活动中创建了新的YouTubePlayerView动态,例如:
YouTubePlayerView youTubePlayerView = new YouTubePlayerView(PlayerActivity.this);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(640, 360);
layoutParams.setMargins(100, 200, 0, 0);
youTubePlayerView.setLayoutParams(layoutParams);
root.addView(youTubePlayerView);
作为代码,“root”是RelativeLayout,youTubePlayerView的大小和边距与每个youTubePlayerView不同;
此代码有时会起作用,但有时不起作用,它会返回以下错误:
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{37ab2582 V.E..... ......ID 0,0-0,0}. The distances between the ancestor's edges and that of the YouTubePlayerView is: left: 0, top: 0, right: 0, bottom: 0 (these should all be positive).
或者这个
W/YouTubeAndroidPlayerAPI: YouTube video playback stopped due to the player's view being too small. The YouTubePlayerView is 0dp wide (minimum is 200dp) and 0dp high (minimum is 110dp).
有没有办法避免它发生,或让它成功播放视频。
我感谢任何帮助。
此致
答案 0 :(得分:0)
根据Official Google Documentation,设置标志会为您留下处理UI元素可见性的任务。
YouTube播放器会检测到正在显示的视图,并会发出警告。
您可以尝试使用以下其中一个标志:
FULLSCREEN_FLAG_ALWAYS_FULLSCREEN_IN_LANDSCAPE:当设备进入横向时,播放器会自动进入全屏模式。
FULLSCREEN_FLAG_CONTROL_ORIENTATION:启用自动控制方向。
FULLSCREEN_FLAG_CONTROL_SYSTEM_UI:启用系统UI的自动控制。
FULLSCREEN_FLAG_CUSTOM_LAYOUT:禁用默认的全屏布局处理程序,使您可以手动控制向全屏布局的转换。