方向发生变化时,YouTubePlayerFragment黑屏 [英] YouTubePlayerFragment black screen on orientation changes

查看:195
本文介绍了方向发生变化时,YouTubePlayerFragment黑屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在方向更改时继续播放YouTubePlayerFragment.

I'm trying to keep playing YouTubePlayerFragment on orientation changes.

代码如下:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
    FrameLayout frameLayout = new FrameLayout(getActivity());
    populateViewForOrientation(inflater, frameLayout);
    return frameLayout;
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    LayoutInflater inflater = LayoutInflater.from(getActivity());
    populateViewForOrientation(inflater, (ViewGroup) getView());
}

private void populateViewForOrientation(LayoutInflater inflater, ViewGroup viewGroup) {
    viewGroup.removeAllViewsInLayout();
    rootView = inflater.inflate(getLayoutResId(), viewGroup);
    ButterKnife.bind(this, rootView);

    if (frYTube != null) {
       FragmentTransaction transaction = getFragmentManager().beginTransaction();
       transaction.replace(R.id.frame, frYTube);
       transaction.commitAllowingStateLoss();
    }
}

片段已替换(我在其中看到文字)并且正在播放音乐,但不是视频-黑屏. 我该如何处理?是否可以取回视频?顺便说一句,如果旋转后下一个视频是对角线,则会显示该视频. 我尝试为当前视频调用pauseplay-它无济于事. 我没有尝试YouTubePlayerView,因为我使用moxy,所以我需要处理片段.

fragment replaced (i see text on it) and the music is playing but instead of video - black screen. How can i deal with it? is it possible to get video back? btw, if after rotation next video is oppenes - the video appears. i've tried to call pause and play for current video - it dosen't help. i haven't try YouTubePlayerView because i use moxy so i need to deal with fragment.

更新

它看起来像使用内部的YouTubePlayerFragment创建自定义视图具有更稳定的行为(然后删除添加视图).但是黑屏问题仍然存在.

it looks like to create custom view with YouTubePlayerFragment inside have more stable behavior (and remove add view then). but the black screen problem still exists.

在这种情况下,可以通过以下方式恢复视频:

it's possible to restore video in this case with:

 mYouTubePlayer.loadVideo(url);
 ...
 public void onLoaded(String s) {
  mYouTubePlayer.seekToMillis(mills);

但是重新加载视频也没有意义,我正试图避免这种情况-延迟出现了

but there is no sense too reload video, i'm trying to avoid this - the delay appears

推荐答案

我发现并起作用的唯一方法是手动处理屏幕方向:

Only way i found and it works is to handle screen orientation manually:

1)添加到您的活动中:

1) add to your activity:

android:configChanges="keyboard|keyboardHidden|orientation|screenSize"

2)在活动课程中:

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

,并且您不应膨胀新的布局.只需删除并重新创建/添加您需要的所有内容即可,除了youtubeframe即可使您所需的土地布局看起来更漂亮.这有点棘手和奇怪,但是在其他情况下,您会看到黑屏而不是视频.

and you shouldn't inflate new layout. just remove and recreate/add all you need except youtubeframe to make land layout looks you want. it's a bit tricky and strange, but in other cases you got black screen instead video.

这篇关于方向发生变化时,YouTubePlayerFragment黑屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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