Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to play video fullscreen with landscape in Android WebView?

  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. enter image description here
like image 501
kevin4z Avatar asked Nov 08 '22 06:11

kevin4z


1 Answers

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;
}
like image 107
Andrijan Stanković Avatar answered Nov 14 '22 22:11

Andrijan Stanković