在Android中,WebView默认是不支持视频全屏播放的,但可以通过以下几种方法实现:
webView.setWebChromeClient(new WebChromeClient() {
@Override
public void onShowCustomView(View view, WebChromeClient.CustomViewCallback callback) {
super.onShowCustomView(view, callback);
// 进入全屏播放
}
@Override
public void onHideCustomView() {
super.onHideCustomView();
// 退出全屏播放
}
});
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.endsWith(".mp4") || url.endsWith(".avi") || url.endsWith(".3gp")) {
VideoView videoView = new VideoView(getApplicationContext());
videoView.setVideoURI(Uri.parse(url));
setContentView(videoView);
videoView.start();
return true;
}
return super.shouldOverrideUrlLoading(view, url);
}
});
implementation 'org.xwalk:xwalk_core_library:23.53.589.4'
implementation 'org.mozilla.geckoview:geckoview-nightly:91.0.0'
通过以上方法,可以实现WebView视频的全屏播放功能。