Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
196 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...