Android 上的 HTML5 <video> 元素无法播放

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2911379/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 07:51:12  来源:igfitidea点击:

HTML5 <video> element on Android does not play

androidvideohtml

提问by T1000

Video tags like below plays fine with iPhone, but not Android:

像下面这样的视频标签在 iPhone 上播放得很好,但在 Android 上则不行:

<video id="video" width="320" height="240" poster="video/placeholder.jpg" autobuffer controls>
  <source src="pr6.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'>
  <source src="pr6.ogv" type='video/ogg; codecs="theora, vorbis"'>
</video>

With the above code, Android can't even click the clip. It would just see the poster image.

使用上面的代码,Android 甚至无法单击剪辑。它只会看到海报图像。

Video tag like below however works with Android:

像下面这样的视频标签适用于 Android:

<video src="vpr6.mp4" poster="video/placeholder.jpg" onclick="this.play();"/>

However, I still need to multiple sources capability (for Firefox ogv support…). Below code does not work (nor do they work if I stick the javascript into the source tags):

但是,我仍然需要多源功能(对于 Firefox ogv 支持...)。下面的代码不起作用(如果我将 javascript 粘贴到源标签中,它们也不起作用):

<video id="video" width="320" height="240" autobuffer controls onclick="this.play();">
  <source src="pr6.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'>
  <source src="pr6.ogv" type='video/ogg; codecs="theora, vorbis"'>
</video>

With above code, the clip is clickable in Android, but still does nothing.

使用上面的代码,剪辑在 Android 中是可点击的,但仍然什么都不做。

Can anyone help?

任何人都可以帮忙吗?

采纳答案by Artiom Chilaru

Try to remove the codecs from the source listings.. It might be that the codecs you're listing are not present on Android, so it's choking.

尝试从源列表中删除编解码器.. 可能是您列出的编解码器在 Android 上不存在,所以它令人窒息。

If you use the src attribute, it'll auto-detect the codec, so it's using something else :)

如果你使用 src 属性,它会自动检测编解码器,所以它使用其他东西:)