问题
- 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.
回答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