What is the proper way to serve mp4 files through rails to an Ipad? -


we're having trouble serving mp4s play on ipad using default rails 3 app. mp4 served correctly when viewing route in chrome , other browsers on desktop.

here our code:

file_path = file.join(rails.root, 'test.mp4') send_file(file_path, :disposition => "inline", :type => "video/mp4") 

we hit 0.0.0.0:3000/video/test.mp4 view video , presented cannot play icon on ipad. we've tried modifying various headers "content-length", "content-range", etc don't seem affect end result.

we've tried using send_data extent

i.e.

file.open(file_path, "r") |f|     send_data f.read, :type => "video/mp4" end  

the same video serves fine public folder when viewed on ipad.

what proper way serve mp4 files through rails ipad?

the problem seems rails doesn't handle http-range requests ios needs streaming mp4s.

this our solution development, (using thin our server):

  if(request.headers["http_range"]) && rails.env.development?      size = file.size(file_path)     bytes = rack::utils.byte_ranges(request.headers, size)[0]     offset = bytes.begin     length = bytes.end - bytes.begin + 1      response.header["accept-ranges"]=  "bytes"     response.header["content-range"] = "bytes #{bytes.begin}-#{bytes.end}/#{size}"     response.header["content-length"] = "#{length}"      send_data io.binread(file_path,length, offset), :type => "video/mp4", :stream => true,  :disposition => 'inline',               :file_name => file_name    else     send_file(file_path, :disposition => 'inline', :stream => true, :file_name => file_name)   end 

ultimately using nginx xsendfile serve assets in our production environment above solution slower need.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -