【问题标题】:Setting Mime Type for .ogv files in Rails Development Environment在 Rails 开发环境中为 .ogv 文件设置 Mime 类型
【发布时间】:2011-02-09 16:18:21
【问题描述】:

我正在玩 HTML5 视频,并且在 ERB 中有以下 sn-p:

<video id="movie" width="320" height="240" poster="/test.jpg" preload="none" controls="">
    <source src="/test.mp4" type="video/mp4; codecs=&quot;avc1.42E01E, mp4a.40.2&quot;">
    <source src="/test.ogv" type="video/ogg; codecs=&quot;theora, vorbis&quot;">
</video>

从我的开发环境中运行的服务器到 chrome 的 mp4 视频流很好。然而,Firefox 显示带有海报图像的视频播放器,但带有一个大 X。问题似乎是 mongrel 不确定 ogv 扩展的 mime 类型,并且只返回 text/plain,如 curl 所示:

$ curl -I http://0.0.0.0:3000/pr6.ogv
HTTP/1.1 200 OK
Connection: close
Date: Mon, 19 Apr 2010 12:33:50 GMT
Last-Modified: Sun, 18 Apr 2010 12:46:07 GMT
Content-Type: text/plain
Content-Length: 13652587

那么我应该在哪里配置才能返回正确的 mime 类型?我已经尝试过各种创造性的搜索来寻找答案,但我能找到的最接近的方法是使用 Mime::Type.register 但是它似乎只处理 responds_to 的东西,当我尝试它时没有任何效果案例。

所以电脑设置?杂种配置? Rails 应用程序配置?不太确定在哪里看,也不是哑剧类型的专家。我的开发环境是 Mac,Rails 2.3.5。

【问题讨论】:

    标签: ruby-on-rails ruby video mime-types


    【解决方案1】:

    我遇到了同样的问题,在这里找到了解决方案:http://9elements.com/io/?p=306

    我正在运行 rails 2.3.5,所以我将以下代码放入 config/initializers/mime_types.rb 中,然后重置我的服务器(我正在使用 WEBrick 进行本地开发)

    Rack::Mime::MIME_TYPES.merge!({
      ".ogg"     => "application/ogg",
      ".ogx"     => "application/ogg",
      ".ogv"     => "video/ogg",
      ".oga"     => "audio/ogg",
      ".mp4"     => "video/mp4",
      ".m4v"     => "video/mp4",
      ".mp3"     => "audio/mpeg",
      ".m4a"     => "audio/mpeg"
    })
    

    现在 curl 显示 ogv 文件的正确 mime 类型。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-03-20
      • 2011-05-11
      • 2014-07-16
      • 1970-01-01
      • 2010-11-01
      相关资源
      最近更新 更多