我想要完成的是,当 a 中有嵌入的 iframe YouTube 视频WebView
并且用户开始播放视频然后单击全屏按钮时,我希望它以全屏显示Dialog
,而不是像https这样的建议://code.google.com/p/html5webview/source/browse/trunk/HTML5WebView/src/org/itri/html5webview/HTML5WebView.java
我在WebView
和 中都播放了视频Dialog
,但是,全屏对话框中没有播放器控件。下面是迄今为止让它在对话框中播放的被黑代码。
webView.setWebChromeClient(new WebChromeClient() {
View mVideoProgressView;
Bitmap mDefaultVideoPoster;
Dialog fullScreenDialog;
WebChromeClient.CustomViewCallback mCustomViewCallback;
@Override
public void onShowCustomView(View view, CustomViewCallback callback) {
super.onShowCustomView(view, callback);
if (view instanceof FrameLayout) {
FrameLayout frameLayout = (FrameLayout) view;
mCustomViewCallback = callback;
fullScreenDialog = new Dialog(DemoActivity.this, R.style.full_screen_dialog);
// fullScreenDialog = new Dialog(DemoActivity.this, R.style.Dialog_Fullscreen);
LinearLayout linearLayout = (LinearLayout) getLayoutInflater().inflate(R.layout.full_screen_video_view, null);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
params.gravity = Gravity.CENTER;
SurfaceView surfaceView = (SurfaceView)frameLayout.getFocusedChild();
surfaceView.bringToFront();
surfaceView.setZOrderMediaOverlay(true);
surfaceView.setZOrderOnTop(true);
surfaceView.setLayoutParams(params);
// frameLayout.removeAllViews();
// linearLayout.addView(surfaceView);
// fullScreenDialog.setContentView(view, params);
frameLayout.removeAllViews();
fullScreenDialog.setContentView(surfaceView);
fullScreenDialog.show();
}
}
@Override
public void onHideCustomView() {
if (fullScreenDialog != null && fullScreenDialog.isShowing()) {
fullScreenDialog.dismiss();
}
if (mCustomViewCallback != null) {
mCustomViewCallback.onCustomViewHidden();
mCustomViewCallback = null;
}
}
@Override
public Bitmap getDefaultVideoPoster() {
if (mDefaultVideoPoster == null) {
mDefaultVideoPoster = BitmapFactory.decodeResource(getResources(), R.drawable.default_video_poster);
}
return mDefaultVideoPoster;
}
@Override
public View getVideoLoadingProgressView() {
if (mVideoProgressView == null) {
LayoutInflater inflater = getLayoutInflater();
mVideoProgressView = inflater.inflate(R.layout.video_loading_progress, null);
}
return mVideoProgressView;
}
});
我的 full_screen_dialog 风格很简单:
<style name="full_screen_dialog">
<!--<item name="android:windowFrame">@null</item>-->
<!--<item name="android:windowIsFloating">true</item>-->
<!--<item name="android:windowContentOverlay">@null</item>-->
<!--<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>-->
<!--<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>-->
<item name="android:windowFullscreen">true</item>
<item name="android:windowNoTitle">true</item>
</style>
这些WebView
设置启用了 javascript 和插件。
此贴有许多类似的问题,但没有一个试图在全屏对话框中打开视频。任何帮助将不胜感激!