我有一个带有片段的应用程序,在这些片段中我有框架布局,我添加了YouTubePlayerSupportFragment。但是当我点击全屏时会抛出此异常:
java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.xxx/com.example.xxx.MainActivity}:java.lang.IllegalArgumentException:找不到id 0x7f040039的视图(com.example.xxx:id / frame_youtube)片段YouTubePlayerSupportFragment {4282a068#11 id = 0x7f040039}
答案 0 :(得分:35)
或者您可以将其禁用1行:
player.setShowFullscreenButton(false);
答案 1 :(得分:17)
我遇到了同样的问题,并找到了一种方法来处理它对我有用。在片段的OnInitializedListener()
中,我这样做:
@Override
public void onInitializationSuccess(Provider arg0,
final YouTubePlayer player, boolean arg2) {
//Tell the player you want to control the fullscreen change
player.setFullscreenControlFlags(YouTubePlayer.FULLSCREEN_FLAG_CUSTOM_LAYOUT);
//Tell the player how to control the change
player.setOnFullscreenListener(new OnFullscreenListener(){
@Override
public void onFullscreen(boolean arg0) {
// do full screen stuff here, or don't. I started a YouTubeStandalonePlayer
// to go to full screen
}});
}});
自从我使用 YouTubeStandalonePlayer 处理我的全屏后,我仍然收到错误,所以我通过调用
解决了这个问题finish();
在我OnPause()
的活动中。请记住,如果用户按下后退按钮,您将不会回到停止的位置。您还可以通过意图将用户发送到YouTube应用,当我测试时,这不需要OnPause中的finish()
,但不符合我的需求以及独立播放器。
编辑:如果您想要删除全屏按钮,您还可以像这样设置播放器样式:
PlayerStyle style = PlayerStyle.MINIMAL;
player.setPlayerStyle(style);
答案 2 :(得分:0)
如果要显示全屏,请youTubePlayer.setFullscreen(true);
如果要在全屏显示后甚至在纵向模式下隐藏全屏按钮,请youTubePlayer.setShowFullscreenButton(false);
您还可以使用最新API中提供的PlayerStyle选项
YouTubePlayer.PlayerStyle.CHROMELESS
一种样式,不显示交互式播放器控件。 (无控件)
YouTubePlayer.PlayerStyle.DEFAULT
默认样式,显示所有交互式控件。 (所有控件)
YouTubePlayer.PlayerStyle.MINIMAL
的最小样式,仅显示时间栏和播放/暂停控件。 (只能暂停/播放)