|
Posted by lawrence k on 09/03/06 05:03
lawrence k wrote:
> The mp3 I'm using to test this code is here:
> http://www.monkeyclaus.org/Enemy.mp3
>
> The code below is at this address:
> http://www.monkeyclaus.org/streamingMedia.php
>
> -------
>
>
> $allBytesInFile = filesize("Enemy.mp3");
> $tenPercentOfFileInBytes = $allBytesInFile * .1;
> $tenPercentOfFileInBytes = round($tenPercentOfFileInBytes );
> // 09-02-06 - this next line is giving me 282548, which is correct, I
> think.
> // That's how many bytes we want to share with the public.
> //echo $tenPercentOfFileInBytes;
>
> $stream = "www.monkeyclaus.org"; // put in whatever stream you want to
> play
> $port = "80"; // put in the port of the stream
> $path = "/Enemy.mp3"; // put in any extra path, this is usually just a
> /
>
> header("Content-type: audio/mpeg");
> $sock = fsockopen($stream,$port);
>
> fputs($sock, "GET $path HTTP/1.0\r\n");
> fputs($sock, "Host: $stream\r\n");
> fputs($sock, "Accept: */*\r\n");
> fputs($sock, "Connection: close\r\n\r\n");
>
> // code from www.php.net, only plays a second of music before quitting
> // while (!feof($sock)) {
> // $buffer = fgets($sock, 4096);
> // echo $buffer;
> // }
>
> for ($i=0; $i < $tenPercentOfFileInBytes;) {
> $buffer = fgets($sock, 4096);
> echo $buffer;
> $i = $i + 4096;
> }
>
> fclose($sock);
Actually, I find that IE is asking me to download this file, and when
it downloads it then triggers my music player, which then correctly
plays the 20% of this song that I've sent. FireFox only plays a second
of the song and then quits.
I'm thinking I've missed some important header? If I point either
browser straight at an MP3 it'll play the whole thing, in browser. What
do I need to do to get that behavior for the byte stream I'm sending
here?
Navigation:
[Reply to this message]
|