goofball has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Serving video files in specific byte-ranges
by Anonymous Monk on Aug 26, 2011 at 15:44 UTC | |
|
Re: Serving video files in specific byte-ranges
by Anonymous Monk on Aug 26, 2011 at 22:24 UTC | |
by goofball (Acolyte) on Aug 31, 2011 at 14:11 UTC | |
by Corion (Patriarch) on Aug 31, 2011 at 14:16 UTC | |
by goofball (Acolyte) on Sep 06, 2011 at 19:29 UTC | |
by Corion (Patriarch) on Sep 06, 2011 at 20:22 UTC | |
by BrowserUk (Patriarch) on Aug 31, 2011 at 14:45 UTC |