Hello, monks!

Seeking your help, as the cosmic entity known as Google seems to be keeping secrets from me on this topic.

I have a web site that serves video files, but I can't just leave the videos in an un-protected directory because only logged-in users must be able to access them. So I wrote a script, which includes the below snippets, to authenticate the user and then read the video file from disc and "print" that data line-by-line as output. This works great for most applications, but now that I'm trying to serve files to mobile devices like iPhone, this method no longer works. In my research I've learned this is because the mobile browser/video player asks the server for certain data ranges of the video file via multiple requests. Any modern HTTP server handles this behavior automatically, but when my script fails to serve the video fie in the requested chunks, the mobile device sees the file as broken and will not play it.

Could anyone please advise me on how to re-work this script so that I can serve video files in the requested byte ranges?

Many thanks.

print "Content-type: video/mp4\n"; print "Content-length: $filesize\n\n"; open(FILE, $path) or die; while(<FILE>) { print } close(FILE);

Or, alternatively:

open my $fh , '<', $path; print $_ while ( sysread $fh, $_ , 8192 ); close $fh;

Unfortunately, neither of these alternatives is working for mobile clients, although both work fine when the client is a desktop browser.

K.I.S.S. me, I'm stupid!

In reply to Serving video files in specific byte-ranges by goofball

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.