所以我创建了一个Android应用程序,可以播放blip.tv和其他各种支持Flash的网站的视频。我使用Webview
来显示视频。这是我的代码:
try{
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
view = new WebView(this);
view.getSettings().setPluginsEnabled(true);
view.getSettings().setPluginState(WebSettings.PluginState.ON);
view.getSettings().setJavaScriptEnabled(true);
view.getSettings().setLoadWithOverviewMode(true);
view.getSettings().setUseWideViewPort(true);
view.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
view.setScrollbarFadingEnabled(true);
// get the html code
String html = getIntent().getStringExtra("VIDEO_CONTENT");
view.loadData(html, "text/html", null);
setContentView(view);
}
catch(Exception e){
}
问题在于android 4(Ice Cream Sandwich)。当我尝试将应用程序置于全屏模式时,应用程序崩溃。该应用程序不会在Android 2.3或3.0上崩溃。有什么想法来解决这个问题吗?
答案 0 :(得分:4)
在ICS中会发生这种情况,因为在尝试进入全屏模式时会调用show()
中的android.webkit.PluginFullScreenHolder
方法。此方法执行以下操作:
WebChromeClient client = mWebView.getWebChromeClient();
client.onShowCustomView(mLayout, mOrientation, mCallback);
如果您未在WebChromeClient
上设置WebView
,您将获得NPE。
这解决了我们的崩溃问题,但WebView消失了,全屏视频也没有显示。
请参阅:Android ICS 4.0 Placing Flash WebView into full screen calls hideAll Method?
***更新:
最终,为了让我的WebView
以全屏模式播放Flash视频,我必须在我的onShowCustomView()
中以类似于以下内容的方式实现WebChromeClient
方法Android浏览器的源代码。我用于灵感的方法的实现是在BaseUI类中:
我并不完全清楚这里发生了什么。我也希望我理解为什么ICS上的开发人员决定要求实现这种方法。我希望我知道价值,或者解决了什么问题。在过去的版本中,这种全屏模式“正常工作”现在需要大量挖掘。
答案 1 :(得分:2)
我遇到了同样的问题。我问过并得到以下答案对我有用。
希望这会对一些人有所帮助:
创建FullscreenableChromeClient和
添加以下行:
WebView.setWebChromeClient( new FullscreenableChromeClient(this));
public class FullscreenableChromeClient extends WebChromeClient {
protected Activity mActivity = null;
private View mCustomView;
private WebChromeClient.CustomViewCallback mCustomViewCallback;
private int mOriginalOrientation;
private FrameLayout mContentView;
private FrameLayout mFullscreenContainer;
private static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
public FullscreenableChromeClient(Activity activity) {
this.mActivity = activity;
}
@Override
public void onShowCustomView(View view, int requestedOrientation, WebChromeClient.CustomViewCallback callback) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
if (mCustomView != null) {
callback.onCustomViewHidden();
return;
}
mOriginalOrientation = mActivity.getRequestedOrientation();
FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
mFullscreenContainer = new FullscreenHolder(mActivity);
mFullscreenContainer.addView(view, COVER_SCREEN_PARAMS);
decor.addView(mFullscreenContainer, COVER_SCREEN_PARAMS);
mCustomView = view;
setFullscreen(true);
mCustomViewCallback = callback;
mActivity.setRequestedOrientation(requestedOrientation);
}
super.onShowCustomView(view, requestedOrientation, callback);
}
@Override
public void onHideCustomView() {
if (mCustomView == null) {
return;
}
setFullscreen(false);
FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
decor.removeView(mFullscreenContainer);
mFullscreenContainer = null;
mCustomView = null;
mCustomViewCallback.onCustomViewHidden();
mActivity.setRequestedOrientation(mOriginalOrientation);
}
private void setFullscreen(boolean enabled) {
Window win = mActivity.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);
}
private static class FullscreenHolder extends FrameLayout {
public FullscreenHolder(Context ctx) {
super(ctx);
setBackgroundColor(ctx.getResources().getColor(android.R.color.black));
}
@Override
public boolean onTouchEvent(MotionEvent evt) {
return true;
}
}
}
答案 2 :(得分:1)
好的,所以我认为这是一个Android 4.0.2 / flash播放器问题,因为当闪光灯进入全屏模式时,browser
和dolphin mini
等其他应用程序会崩溃。