video 满屏显示_显示HTML5视频全屏

I have a webview that has html video inside it. I want to show this video fullscreen so I override onShowCustomView of my WebChromeClient to use a VideoView. This works great in 2.3, however, in 4.x onShowCustomView is never called. The video will still play, however, it is played from within the webview without any controls besides clicking for play and stop.

Also, I have hardwareAccelerated="true".

Any idea why onShowCustomView is never called?

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

webView = (WebView) findViewById(R.id.webView);

webView.getSettings().setSupportZoom(true);

webView.getSettings().setLoadWithOverviewMode(true);

webView.getSettings().setUseWideViewPort(true);

webView.getSettings().setBuiltInZoomControls(true);

webView.getSettings().setJavaScriptEnabled(true);

webView.getSettings().setDomStorageEnabled(true);

webView.getSettings().setPluginState(WebSettings.PluginState.ON);

webView.setWebViewClient(new WebViewClient());

webView.setWebChromeClient(new MyChromeClient());

webView.loadUrl(URL);

}

private class MyChromeClient extends WebChromeClient implements

OnCompletionListener, OnErrorListener, OnPreparedListener {

@Override

public void onShowCustomView(View view, CustomViewCallback callback) {

Log.d("ma", "onShowCustomView");

}

...

解决方案

Well after struggling with this for a while, I finally found the cause. In Android 4.x you must show the controls by using the html 'controls' attribute in the 'video' tag. Once you are showing these controls, you can click on the fullscreen button which will then call 'onShowCustomView'. Since embedded video is available in 4.x and you have the option to go to fullscreen with the controls, onShowCustomView will not be called automatically on play. Unfortunately, this is very poorly documented in the Android documentation.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值