Android HTML5 video in WebView

混江龙づ霸主 提交于 2019-12-14 03:34:33

问题


I am attempting to play an HTML5 video within my WebView app. It works as expected on every device I have tested that is running Android 5.x, but does not work on any device running 4.x, meaning it essentially doesn't work at all.

I have turned on hardware acceleration and I have set a WebChromeClient as the docs say to do, but the video still will not play.

In order to support inline HTML5 video in your application, you need to have hardware acceleration turned on, and set a WebChromeClient.

AndroidManifest.xml

<application>
    android:hardwareAccelerated="true"
    ... 
</application>

MyFragment.java

webView = new WebView(getActivity(), null, this);
webView.setWebChromeClient(new WebChromeClient());

Is there something else I need to do that is not documented in the developer reference?


回答1:


The problem is WebKit poorly handles redirects for videos. There are videos within webpages from my company's proprietary API. When a video is clicked, the call goes to our API, then redirects to Amazon S3 to get the actual video file. WebKit then tries to "chunk" the video (instead of pre-loading the entire thing) as you would expect. However, S3 has already done that, which causes the playback to be completely broken.

Android 5.x works fine because WebView is based upon Chromium starting in 4.4, which handles the redirect appropriately.



来源:https://stackoverflow.com/questions/29569664/android-html5-video-in-webview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!