Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting Mime Type for .ogv files in Rails Development Environment

I am playing around with HTML5 video and have the following snippet in an ERB:

<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>

The mp4 video streams just fine from the server running in my development environment into the chrome. However firefox displays the video player with the poster image, but with a big X. The problem seems to be that mongrel is unsure of the mime type for the ogv extenstion and just returns text/plain as shown by 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

So where do I configure things so that the correct mime type will be returned? I have tried all sorts of creative searching for an answer, but the closest thing I can find is using Mime::Type.register however that only seems to deal with the responds_to stuff and didn't have any effect when I tried it just in case.

So computer setting? Mongrel config? Rails App Config? Not really sure where to look and non an expert in mime types. My dev environement is a Mac, Rails 2.3.5.

like image 813
tmorse Avatar asked Apr 19 '10 12:04

tmorse


1 Answers

I had the same problem, and found the solution here: http://9elements.com/io/?p=306

I'm running rails 2.3.5, so I put the following code in config/initializers/mime_types.rb and then reset my server (I'm using WEBrick for local development)

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"
})

And now curl is showing the correct mime types for ogv files.

like image 200
rayan Avatar answered Oct 01 '22 03:10

rayan