Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

[PATCH] support Range and If-Range on send_file and send_data

#3358

We can stream multimedia data (videos, audios and so on) by send_file and/or send_data.

In HTML5, we can use and tag to play videos and audios on browser.
Many modern browsers, Firefox, Safari, Google Chrome and so on, support them.

For example, you can see Ogg/Theora video on Firefox at:
http://commons.wikimedia.org/wiki/File:Firefox_3.1b1_pre_(native_Vi...

You will see a control bar which includes play/suspend button, progress bar and volume control at the bottom of video player.

The current Firefox Ogg/Theora video player implementation requires HTTP "Range" supported HTTP server to display total length at the right of progress bar. If a HTTP server doesn't support "Range", progress bar doesn't work. It always indicates the end.
NOTE: Movie can be played correctly even if progress bar doesn't show correct progress.

In Rails, we use send_file and/or send_data to stream movies and/or audios but Rails doesn't support "Range". So we can't play a movie streamed by Rails with correct progress.

Here is a sample Rails application:

% ruby .../edge-rails/railties/bin/rails sample
% cd sample
% ln -fs .../edge-rails vendor/rails
% script/generate controller Streaming index
% vim app/controllers/streaming_controller.rb
app/controllers/streaming_controller.rb:
  class StreamingController < ApplicationController
    def index
      send_file(Rails.root.join("sample.ogv"), :layout => false, :type => "video/ogg")
    end
  end
% wget -O sample.ogv 'http://upload.wikimedia.org/wikipedia/commons/7/79/Firefox_3.1b1_pre_%28native_Videounterst%C3%BCtzung%29.ogg'
% script/server &
% vim /tmp/video.html
/tmp/video.html:
  <html>
    <body>
      <video src="http://localhost:3000/streaming/" controls="true" />
    </body>
 </html>
% firefox /tmp/video.html

You play the movie and then you will notice that progress bar is always filled and total length just indicates played time.

The attached patch supports HTTP "Range" and "If-Range". You will get correct progress with patched Rails.

Reported by Kouhei Sutou · October 9th, 2009 @ 07:16 AM

State: stale
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Sidney
    Sidney

    Problem verified Rails 3.0.0 beta2

    April 11th, 2010 @ 11:11 PM

  2. Sidney
    Sidney
    • Assigned user set to Ryan Bigg

    April 12th, 2010 @ 02:07 AM

  3. Ryan Bigg
    Ryan Bigg
    • Assigned user cleared.

    I am not responsible for applying patches, only marking tickets as invalid / whatever in the system. I will, however, take a look at this patch and provide feedback later tonight.

    April 12th, 2010 @ 02:11 AM

  4. Yehuda Katz (wycats)
    Yehuda Katz (wycats)
    • State changed from new to incomplete

    This patch no longer applies due to the change to using a SendFile middleware

    April 13th, 2010 @ 05:25 AM

  5. Santiago Pastorino
    Santiago Pastorino
    • State changed from incomplete to open
    • Importance changed from to

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 2nd, 2011 @ 04:43 PM

  6. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 04:43 PM