是否有可能禁用全屏YouTube的API中的android?有可能、全屏、YouTube、API

2023-09-07 04:35:55 作者:じAomrご心渃相依つ

由于头说:是可以禁用全屏幕在Android上的Youtube API

我有一个片段,一个应用程序和那些片段里面我有框架布局到我补充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}

解决方案

我面临着同样的问题,并找到一种方法来处理它是为我工作。在OnInitializedListener()的片段,我这样做:

  @覆盖
公共无效onInitializationSuccess(供应商为arg0,
最后YouTubePlayer球员,布尔ARG2){
//告诉玩家要控制全屏变
player.setFullscreenControlFlags(YouTubePlayer.FULLSCREEN_FLAG_CUSTOM_LAYOUT);
//告诉玩家如何控制变化
player.setOnFullscreenListener(新OnFullscreenListener(){
@覆盖
公共无效onFullscreen(布尔为arg0){
//全屏幕的东西在这里,还是没有。我开始YouTubeStandalonePlayer
//进入全屏
}});

}});
 

和我仍然有一个错误,因为我用YouTubeStandalonePlayer来处理我的全屏幕,让我解决了通过调用

 结束();
 

在我将OnPause()的活性。只要记住你会不会回来你留下来,如果你的用户点击后退按钮。您也可以通过一个意图向用户发送YouTube应用程序,这并不需要在将OnPause结束()时,我测试过,但没有适合我的需要,以及独立的播放器。

编辑:如果您要删除的全屏按钮,你也可以设置播放器的风格是这样的:

  PlayerStyle风格= PlayerStyle.MINIMAL;
player.setPlayerStyle(风格);
 
使用安卓Youtube API播放youtube视频

As header says: is it possible to disable full screen with the Youtube API in Android?

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: 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}

解决方案

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
}});

}});

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

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.

Edit: 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);