Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 VIDEO is not working in my rails 3 app

I am trying to display HTML5 video in my Rails 3 app in development,i am using Sqlite3 and default webserver(Webrick).I put the video file (movie.ogg) under assets (assets/movie.ogg).The video window screen shows up but there is no video on there though.I have 3 questions...Since rails app assets doesn't have sub-folder for video(as the way it has images),where do you put video files? Does Webrick support Html5 video?Here is my code below ,what am i missing here,to make the video work?

view

       <video width="320" height="240" controls="controls">
       <source src="/assets/movie.mp4" type="video/mp4" />
       <source src="/assets/movie.ogg" type="video/ogg" />
       <source src="/assets/movie.webm" type="video/webm" />
         Your browser does not support the video tag.
       </video>

config/initializers/mime_types.rb

  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"
})
like image 835
katie Avatar asked Jan 13 '12 21:01

katie


2 Answers

The video_tag helper builds an HTML 5 <video> tag.

By default, files are loaded from public/videos. To load from assets/video add the following line to your config/application.rb file:

config.assets.paths << "#{Rails.root}/app/assets/videos"

Tag Usage:

<%= video_tag (["movie.mp4", "movie.ogg", "movie.webm"] :size => "320x240", :controls => true, :autobuffer => true) %>
like image 57
Pragnesh Vaghela Avatar answered Sep 21 '22 18:09

Pragnesh Vaghela


The assets pipeline is used for static assets. If you're adding video files to your app often, you should put them somewhere else (for example, public/videos or public/system/videos). If they really are static assets, try restarting your server first.

like image 38
Nick Colgan Avatar answered Sep 19 '22 18:09

Nick Colgan