Hello,

So I've heard around you can stream MP3's to iPhones using PHP.
Although its not very well documented, I've managed to gather what
eactly is going on.

QT Asks for the file
 -> Server replies with size, content type and that it accepts ranges
in bytes.

QT Asks again, with a small range
 -> Server replies with the size, partial content header, length of
the response, the range of the returned bytes and the content type.

If only it worked.
The exact header I've returned are:
(1st Request):

        print "Accept-Rages: bytes\r\n";
        print "Content-length: 10169832\r\n";
        print "Content-type: audio/mpeg\r\n\r\n";
        print "Content...";


(2nd Request):
        print "HTTP/1.1 206 Partial Content\r\n";
        print "Accept-Ranges: bytes\r\n";
        print "Content-Length: $read_for\r\n";
        print "Content-Range: bytes $ranges/10169832\r\n";
        print "Content-type: audio/mpeg\r\n\r\n";

       #Prints the output...

The exact code is as follows:

#!/usr/bin/perl
if ($ENV{'HTTP_RANGE'}){
        ($NULL,$ranges) = split(/\=/,$ENV{'HTTP_RANGE'});
        chomp($ranges);
        ($offset,$read_till) = split(/\-/,$ranges);
        $printed = $offset;
        $read_for = $read_till - $offset;

        $read_for++;

        $date = `date`;
        print "HTTP/1.1 206 Partial Content\r\n";
        print "Accept-Ranges: bytes\r\n";
        print "Content-Length: $read_for\r\n";
        print "Content-Range: bytes $ranges/10169832\r\n";
        print "Content-Expires: $date\r\n";
        print "Content-type: audio/mpeg\r\n\r\n";

        open(READER,"./song.mp3");
        binmode READER;
        while (<READER>){
                seek(READER,$printed,0);
                sysread(READER,$out,$read_for,0);
                print $out;
                $printed = $printed + $read_for;
                close(READER);
        }


}else{
        print "Accept-Rages: bytes\r\n";
        print "Content-length: 10169832\r\n";
        print "Content-type: audio/mpeg\r\n\r\n";
        print "Content...";
        exit;
}



Any help would be greately appreciated.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"iPhoneWebDev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/iphonewebdev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to