How to play video fullscreen with landscape in Android WebView?

无人久伴 提交于 2021-01-21 09:15:24

问题


  1. 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.
  2. But when I clcik 'Fullscreen' button, the video just moving to center in the vertical direction(portrait).
  3. So, my question is how to set fullscreen in landscape? Thank you.

回答1:


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);

In Activity I changed line in OnToggledFullscreenCallback

 getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE)

to

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);

so that it hides navigation bar.

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;
}


来源:https://stackoverflow.com/questions/40343839/how-to-play-video-fullscreen-with-landscape-in-android-webview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!