WebView中的Android HTML5视频 [英] Android HTML5 video in WebView

查看:92
本文介绍了WebView中的Android HTML5视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的WebView应用中播放HTML5视频。它在我测试的运行Android 5.x的每台设备上按预期工作,但适用于运行 4.x 的任何设备,这意味着它基本上不会工作。

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.

我已经开启了硬件加速,我设置了一个WebChromeClient 文档说要做,但视频仍无法播放。

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.


为了在您的应用程序中支持内联HTML5视频,您需要
才能启用硬件加速,并设置WebChromeClient。

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?

推荐答案

问题是WebKit很难处理视频的重定向。我公司专有API的网页中有视频。单击视频时,呼叫将转到我们的API,然后重定向到Amazon S3以获取实际的视频文件。然后,WebKit尝试按照您的预期分块视频(而不是预先加载整个视频)。但是,S3已经这样做了,这导致播放完全被打破。

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工作正常,因为WebView基于Chromium,从4.4开始,处理适当的重定向。

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

这篇关于WebView中的Android HTML5视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆