我在React Native应用程序中运行自定义版本的Cordova WebView。在网站上,有一个嵌入式视频,例如来自YouTube,我的CDN等,它包含在<iframe>
标签中。当我点击全屏时,屏幕变黑,我只听到音频播放。
我试图修复StackOverflow上的许多建议,例如:
android:hardwareAccelerated=true
onShowCustomView
和onHideCustomView
: @Override
public void onShowCustomView(View v, WebChromeClient.CustomViewCallback cb) {
if (mVideoView != null) {
cb.onCustomViewHidden();
} else {
FrameLayout f = (FrameLayout) v;
mVideoView = v;
mWebView.setVisibility(View.GONE);
f.getChildAt(0).setFocusable(true);
mCustomView = new FrameLayout(mWebView.getContext());
mCustomView.setVisibility(View.VISIBLE);
mCustomView.addView(mVideoView);
getWebViewParent().addView(mCustomView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
mVideoCallback = cb;
}
}
@Override
public void onHideCustomView() {
super.onHideCustomView();
if (mVideoView == null) {
return;
}
mWebView.setVisibility(View.VISIBLE);
mCustomView.setVisibility(View.GONE);
mVideoView.setVisibility(View.GONE);
mCustomView.removeView(mVideoView);
getWebViewParent().removeView(mCustomView);
mVideoCallback.onCustomViewHidden();
mVideoView = null;
}
问题没有解决,似乎没有任何改变。调试器上的堆栈跟踪显示: - 参数View v
的(唯一)子节点未聚焦 - 视频视图的类是FullScreenView
,属于Android chrome。
解决此问题的建议解决方案是什么?谢谢。
解决方案正确发布在这里:Webview and iFrame Video full screen issue
基本上问题是VideoView不应该位于WebView的相同层次结构或子视图层次结构中。在Java中快速实现onShowCustomView
将如下所示:
mVideoView.setLayout(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
mVideoView.setVisibility(View.VISIBLE);
webViewRoot.addView(mVideoView);
webViewDirectParent.setVisibility(View.GONE);