我正在构建一个依赖于能够在WebView中播放Flash的应用程序,并且发现一切都按预期工作,直到Flash视频全屏显示。当请求全屏时,屏幕变黑并且音频持续约5秒钟。
我最初发现屏幕是白色的,但是在下面的文章中调整了解决方案,这已经移动了目标帖子。 Android ICS 4.0 Placing Flash WebView into full screen calls hideAll Method?
final WebView mWebView = (WebView)findViewById(R.id.webview);
WebSettings webSettings = mWebView.getSettings();
webSettings.setPluginState(WebSettings.PluginState.ON);
webSettings.setJavaScriptEnabled(true);
mWebView.requestFocusFromTouch();
mWebView.setWebViewClient(new WebViewClient());
mWebView.setWebChromeClient(new WebChromeClient(){
public void onShowCustomView(View view, int requestedOrientation, WebChromeClient.CustomViewCallback callback){
super.onShowCustomView(view, callback);
if(Build.VERSION.SDK_INT >=14) {
if (view instanceof FrameLayout) {
mWebView.addView(view, new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT,
Gravity.CENTER));
mWebView.setVisibility(View.VISIBLE);
}
}
}
});
当全屏Flash视频开始时,我在logcat中看到以下内容。
08-11 15:09:47.435:V / VideoSurfaceView(23871):surfaceCreated
08-11 15:09:47.435:V / VideoSurfaceView(23871):surfaceChanged format = 842094169,width = 480,height = 690
以下答案引用了从浏览器实现类似于BaseUI类的onShowCustomView。有一个非常类似的方法叫做showCustomView,我试图破解我的代码来添加BaseUI类的内容,并且我设法让我的代码编译和运行,但它并没有让你的代码有点不同。 / p>
flash player crashes when trying to enter fullscreen mode android 4.0
提前感谢您的想法和帮助......
答案 0 :(得分:2)
在进行了一些挖掘之后,我已经回答了我的问题,这让我陷入了下一组问题,我将把这些问题作为单独的问题发布。
以下代码将从webView全屏显示Flash,只要Flash不请求方向更改即可。它还打破了源webView,因为我在排除“指定的子节点已经有父节点”崩溃后被迫添加了removeAllViews()方法。
同时使用WebView作为最后一个允许从重写的WebChromeClient方法进行访问的实现会破坏需要访问此WebView的任何其他方法
public void startWebView(String url){
final WebView mWebView = (WebView)findViewById(R.id.webview);
final Context ctx = this;
WebSettings webSettings = mWebView.getSettings();
webSettings.setBuiltInZoomControls(true);
webSettings.setPluginState(WebSettings.PluginState.ON);
webSettings.setJavaScriptEnabled(true);
webSettings.setLoadWithOverviewMode(true);
mWebView.requestFocusFromTouch();
mWebView.setWebViewClient(new WebViewClient());
mWebView.setWebChromeClient(new WebChromeClient(){
protected WebView tempView;
public void onShowCustomView(View view, int requestedOrientation, WebChromeClient.CustomViewCallback callback){
super.onShowCustomView(view, callback);
if(Build.VERSION.SDK_INT >=14) {
if (view instanceof FrameLayout) {
mWebView.addView(view, new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT,
Gravity.CENTER));
mWebView.setVisibility(View.VISIBLE);
}
}
if (mCustomView != null) {
callback.onCustomViewHidden();
return;
}
mOriginalOrientation = activity.getRequestedOrientation();
FrameLayout decor = (FrameLayout) activity.getWindow().getDecorView();
mWebView.setVisibility(View.INVISIBLE);
mFullscreenContainer = new FullscreenHolder(ctx);
mWebView.removeAllViews();
mFullscreenContainer.addView(view, COVER_SCREEN_PARAMS);
decor.addView(mFullscreenContainer, COVER_SCREEN_PARAMS);
mCustomView = view;
setFullscreen(true);
mCustomViewCallback = callback;
activity.setRequestedOrientation(requestedOrientation);
}
public void onHideCustomView() {
if(debug==true)Log.d(name,"onHide start");
mWebView.setVisibility(View.VISIBLE);
if(debug==true)Log.d(name,"onHide ");
if (mCustomView == null)
return;
setFullscreen(false);
FrameLayout decor = (FrameLayout) activity.getWindow().getDecorView();
decor.removeView(mFullscreenContainer);
mFullscreenContainer = null;
mCustomView = null;
mCustomViewCallback.onCustomViewHidden();
if(debug==true)Log.d(name,"onHide callback");
// Show the content view.
activity.setRequestedOrientation(mOriginalOrientation);
if(debug==true)Log.d(name,"onHide set orientation");
mWebView.loadUrl("http://crooksandliars.com/susie-madrak/scott-brown-cries-over-poor-people-ge");
if(debug==true)Log.d(name,"onHide start webview");
}
public void setFullscreen(boolean enabled) {
Window win = activity.getWindow();
WindowManager.LayoutParams winParams = win.getAttributes();
final int bits = WindowManager.LayoutParams.FLAG_FULLSCREEN;
if (enabled) {
winParams.flags |= bits;
} else {
winParams.flags &= ~bits;
if (mCustomView != null) {
mCustomView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
} else {
mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
}
}
win.setAttributes(winParams);
}
});
mWebView.loadUrl(url);
}
static class FullscreenHolder extends FrameLayout {
public FullscreenHolder(Context ctx) {
super(ctx);
setBackgroundColor(00000);
}
@Override
public boolean onTouchEvent(MotionEvent evt) {
return true;
}
}