如何在 Android WebView 中以横向方式全屏播放视频? [英] How to play video fullscreen with landscape in Android WebView?
本文介绍了如何在 Android WebView 中以横向方式全屏播放视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
- 我想在 Android
WebView
中全屏播放视频,所以我使用 HTML5 标签并将这些网络文件放入 src/main/asset/... 文件夹.
- 但是当我点击全屏"按钮时,视频只是移动到垂直方向的中心(纵向).
- 那么,我的问题是如何设置横向全屏?谢谢你.
- I want to play video fullscreen in Android
WebView
, so I use HTML5 tag<video>
and put these web files into src/main/asset/... folder. - But when I clcik 'Fullscreen' button, the video just moving to center in the vertical direction(portrait).
- So, my question is how to set fullscreen in landscape? Thank you.
推荐答案
我使用了 cprcrack/VideoEnabledWebView和 RotatedVerticalFrameLayout.我刚刚更改了 VideoEnabledWebChromeClient 中 onShowCustomView(View view, CustomViewCallback callback) 的一部分.
I used cprcrack/VideoEnabledWebView and RotatedVerticalFrameLayout. I just changed part of onShowCustomView(View view, CustomViewCallback callback) in VideoEnabledWebChromeClient.
// Hide the non-video view, add the video view, and show it
activityNonVideoView.setVisibility(View.INVISIBLE);
Point screenSize = Utils.getDisplaySize(activityNonVideoView.getContext());
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(screenSize.y, screenSize.x);
params.gravity = Gravity.BOTTOM;
videoViewContainer.setLayoutParams(params);
activityVideoView.addView(videoViewContainer);
activityVideoView.setVisibility(View.VISIBLE);
在活动中,我在 OnToggledFullscreenCallback 中更改了行
In Activity I changed line in OnToggledFullscreenCallback
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE)
到
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
以便它隐藏导航栏.
为了获得我使用的显示尺寸
For getting display size I used
public static Point getDisplaySize(Context context) {
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
Point size = new Point();
display.getRealSize(size);
return size;
}
这篇关于如何在 Android WebView 中以横向方式全屏播放视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文