Html 视频文件 .ogv 在 Firefox 中本地播放,而不是从服务器播放

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6139969/
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-29 08:47:17  来源:igfitidea点击:

Video file .ogv plays locally in Firefox, but not from server

firefoxhtmlvideoogg

提问by Pippa

I'm not having any problems playing this video in Chrome, Safari or Opera. When I try to play it in Firefox, I get a grey box with no video. Here is my code:

我在 Chrome、Safari 或 Opera 中播放此视频没有任何问题。当我尝试在 Firefox 中播放它时,我得到一个没有视频的灰色框。这是我的代码:

            <video width="640" height="360" autobuffer controls preload="auto" >
              <source src="fracWelDay3.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'>
            ? <source src="fracWelDay3.webm" type='video/webm; codecs="vp8, vorbis"'>
              <source src="fracWelDay3.ogv" type='video/ogg; codecs="theora, vorbis"'>
                Your browser does not support the video tag.
          </video>

I have also created an .htaccess file (see below) and put it in the same folder as my video files:

我还创建了一个 .htaccess 文件(见下文)并将其放在与我的视频文件相同的文件夹中:

AddType audio/ogg oga ogg AddType video/ogg ogv AddType video/mp4 .mp4 AddType video/webm .webm

AddType 音频/ogg oga ogg AddType 视频/ogg ogv AddType 视频/mp4 .mp4 AddType 视频/webm .webm

The link to my file is:

我的文件的链接是:

http://www.synergese.co.uk/testMathsOnline/day3/videos/day3FracWelVideo.html

http://www.synergese.co.uk/testMathsOnline/day3/videos/day3FracWelVideo.html

I would be very grateful for any help.

我将不胜感激任何帮助。

Many thanks, Philippa

非常感谢,菲利帕

回答by rjb

The MIME-type from your server for the fracWelDay3.ogvvideo is incorrectly being served as `text/plain'.

来自您服务器的fracWelDay3.ogv视频MIME 类型错误地作为“文本/纯文本”提供。

$ curl -I http://www.synergese.co.uk/testMathsOnline/day3/videos/fracWelDay3.ogv

$ curl -I http://www.synergese.co.uk/testMathsOnline/day3/videos/fracWelDay3.ogv

Notice that Content-Typeis text/plaininstead of video/ogg:

请注意,Content-Type的text/plain不是video/ogg

HTTP/1.1 200 OK
Date: Thu, 26 May 2011 21:55:25 GMT
Server: LiteSpeed
Accept-Ranges: bytes
Connection: close
ETag: "fa8cc4-4dde175c-0"
Last-Modified: Thu, 26 May 2011 09:03:24 GMT
Content-Type: text/plain
Content-Length: 16420036

The HTML5 video plays for me in Safari, Chrome and IE 9 but not Firefox or IE 7-8. If you fix the MIME-type issue, it will play in Firefox.

HTML5 视频可以在 Safari、Chrome 和 IE 9 中播放,但不能在 Firefox 或 IE 7-8 中播放。如果您修复MIME 类型问题,它将在 Firefox 中播放。

If you're using the Apache web server or some derivative of Apache, you can use an AddType directivein your site-wide httpd.confor in an .htaccess filein the directory where you store your video files. (If you use some other web server, consult your server's documentation on how to set the Content-Type HTTP header for specific file types.)

如果您使用的是 Apache Web 服务器或 Apache 的某些衍生产品,则可以AddType directive在站点范围内httpd.conf或在.htaccess file存储视频文件的目录中使用 。(如果您使用其他 Web 服务器,请查阅您服务器的文档,了解如何为特定文件类型设置 Content-Type HTTP 标头。)

AddType video/ogg .ogv
AddType video/mp4 .mp4
AddType video/webm .webm

The first line is for videos in an Ogg container. The second line is for videos in an MPEG-4 container. The third is for WebM. Set it once and forget it. If you forget to set it, your videos will fail to play in some browsers, even though you included the MIME type in the type attribute in your HTML markup.

第一行用于 Ogg 容器中的视频。第二行用于 MPEG-4 容器中的视频。第三个是针对 WebM。设置一次,忘记它。如果您忘记设置它,您的视频将无法在某些浏览器中播放,即使您在 HTML 标记的 type 属性中包含了 MIME 类型。