在 html 页面中嵌入视频并使其播放本地驱动器中的任何视频文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10429629/
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
embed video in html page and make it play any video file in local drive
提问by damon
I want to embed video in html page sothat I can play any multimedia file from my hard drive or from a url.I tried to create a web page with
我想在 html 页面中嵌入视频,以便我可以播放硬盘驱动器或 url 中的任何多媒体文件。我尝试创建一个网页
<video src="test.mp4" controls width="320" height="240">
</video>
In chrome
,the video plays without any problem.
However,the mp4 file is not recognized in firefox
.It displays error message- 'no video with supported format or mimetype found'.
在chrome
,视频播放没有任何问题。但是,mp4 文件在firefox
.It 中无法识别。它显示错误消息-'no video with supported format or mimetype found'.
It so happens that most of my video files are .mp4 or .flv
files.
碰巧我的大部分视频文件都是.mp4 or .flv
文件。
If I put
<source src="test.flv" />
in the video element ,then both chrome and firefox fail to show it.
如果我放入
<source src="test.flv" />
视频元素,那么 chrome 和 firefox 都无法显示它。
So,what should I do to play at least mp4 and flv files in both browsers
?.
那么,我该怎么玩呢at least mp4 and flv files in both browsers
?。
Any pointers /advice most appreciated.
任何指针/建议最受赞赏。
采纳答案by Anthony
From Mozilla's page on browser-supported audio/video formats:
从 Mozilla 的关于浏览器支持的音频/视频格式的页面:
The MPEG container format with the H.264 video codec and either the AAC audio codec or the MP3 audio codec is supported by Internet Explorer and Safari. Firefox and Opera do not support the format. Support for the format is deprecated in Chrome, and Chromium does not support it either.
The MPEG media formats are covered by patents, which are not freely licensed. All the necessary licenses can be bought from MPEG LA. Since H.264 is currently not a royalty free format, it is unfit for the open web platform, according to Mozilla [1, 2], Google [1, 2] and Opera.
Internet Explorer 和 Safari 支持带有 H.264 视频编解码器和 AAC 音频编解码器或 MP3 音频编解码器的 MPEG 容器格式。Firefox 和 Opera 不支持该格式。Chrome 已弃用该格式,Chromium 也不支持该格式。
MPEG 媒体格式受专利保护,不能自由授权。所有必要的许可证都可以从 MPEG LA 购买。根据 Mozilla [1, 2]、Google [1, 2] 和 Opera 的说法,由于 H.264 目前不是免版税格式,因此不适合开放网络平台。
Short answer, Firefox doesn't support mp4, as it's not open source. But it does support multiple sources and will play the first one it supports.
简短的回答,Firefox 不支持 mp4,因为它不是开源的。但它确实支持多个来源,并且会播放它支持的第一个来源。
Further, it doesn't appear that swf or flv are supported by any browsers, since they are totally Adobe and require Flash Player, but the following should work around that:
此外,似乎没有任何浏览器支持 swf 或 flv,因为它们完全是 Adobe 并且需要 Flash Player,但以下应该解决这个问题:
<video src="test.mp4" controls>
<object data="test.flv" type="application/x-shockwave-flash">
<param value="test.flv" name="movie"/>
</object>
</video>
Be aware that the above had .swf
file as data and value originally; I haven't tested if .flv
will work on its own.
请注意,上面的.swf
文件最初是作为数据和值的;我还没有测试过是否.flv
可以单独工作。