Android WebView播放视频全屏
程序员文章站
2024-03-17 12:00:16
...
private View mCustomView;
private int mOriginalSystemUiVisibility;
private WebChromeClient mWebChromeClient;
private WebChromeClient.CustomViewCallback mCustomViewCallback;
mWebChromeClient = new WebChromeClient() {
@Override
public void onShowCustomView(View view, CustomViewCallback callback) {
super.onShowCustomView(view, callback);
// if a view already exists then immediately terminate the new one
if (mCustomView != null) {
onHideCustomView();
return;
}
// 1. Stash the current state
mCustomView = view;
mCustomView.setBackgroundColor(Color.WHITE);
mOriginalSystemUiVisibility = getWindow().getDecorView().getSystemUiVisibility();
// 2. Stash the custom view callback
mCustomViewCallback = callback;
// 3. Add the custom view to the view hierarchy
FrameLayout decor = (FrameLayout)getWindow().getDecorView();
decor.addView(mCustomView, new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
// 4. Change the state of the window
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_FULLSCREEN |
View.SYSTEM_UI_FLAG_IMMERSIVE);
}
@Override
public void onHideCustomView() {
super.onHideCustomView();
// 1. Remove the custom view
FrameLayout decor = (FrameLayout)getWindow().getDecorView();
decor.removeView(mCustomView);
mCustomView = null;
// 2. Restore the state to it's original form
getWindow().getDecorView().setSystemUiVisibility(mOriginalSystemUiVisibility);
// 3. Call the custom view callback
mCustomViewCallback.onCustomViewHidden();
mCustomViewCallback = null;
}
};
mWebView.setWebChromeClient(mWebChromeClient);
推荐阅读
-
Android Webview中解决H5的音视频不能自动播放的问题
-
Android WebView播放视频全屏
-
Android WebView加载H5音视频自动播放、关闭Activity停止播放
-
android recyclerview列表播放视频视频全屏翻页自动播放高仿微视之路
-
android webview播放视频自动全屏
-
Android 手机自动灭屏进入演示模式循环播放视频功能
-
[原创] 使用 Vitamio 播放视频作为 Splash 时出现失真情况的解决方案 博客分类: Android androidvideovitamiosplash
-
android之视频播放系统VideoView和自定义VideoView控件的应用 VideoAndroid自定义控件Android视频视频
-
Android使用VideoView播放本地视频和网络视频的方法
-
Android播放assets文件里视频文件相关问题分析