禁用YouTube API的全屏显示 [英] Disable full screen for youtube api

查看:104
本文介绍了禁用YouTube API的全屏显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有片段的应用程序,在这些片段中,我具有框架布局,并向其中添加了YouTubePlayerSupportFragment.但是,当我单击全屏显示时,会引发此异常:

I have an app with fragments and inside those fragments I have frame layout into which I add YouTubePlayerSupportFragment. But when I click full screen then this exception is thrown:

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}

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.xxx/com.example.xxx.MainActivity}: java.lang.IllegalArgumentException: No view found for id 0x7f040039 (com.example.xxx:id/frame_youtube) for fragment YouTubePlayerSupportFragment{4282a068 #11 id=0x7f040039}

推荐答案

我遇到了同样的问题,并找到了一种对我有用的方法.在片段的OnInitializedListener()中,我这样做:

I faced the same issue and found a way to handle it that worked for me. In the OnInitializedListener() for the fragment, I do this:

@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 处理全屏屏幕,我仍然遇到错误,因此我通过致电

And I still got an error since I used the YouTubeStandalonePlayer to handle my full screen, so I solved that by calling

finish(); 

我的OnPause()中的

.请记住,如果用户单击后退"按钮,您将不会回到上次停止的位置.您也可以通过意图将用户发送到YouTube应用,这在我测试时不需要OnPause中的finish(),但不如独立播放器那样适合我的需求.

in my OnPause() for the activity. Just remember you won't come back to where you left off if your user hits the back button. You could also send the user to the YouTube app through an intent, this did not require the finish() in OnPause when I tested it, but did not suit my needs as well as the standalone player.

编辑:如果要删除全屏按钮,还可以像这样设置播放器样式:

If you want to remove the full-screen button, you can also just set the player style like this:

PlayerStyle style = PlayerStyle.MINIMAL;
player.setPlayerStyle(style);

这篇关于禁用YouTube API的全屏显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆