在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視頻的全屏播放功能。