|
Posted by lawrence k on 09/03/06 18:45
Let me change the question that I'm asking. If a person points their
browser straight at an MP3, often the browser will start playing the
MP3 as it downloads (this is true for FireFox and IE on a PC, Safari on
the Mac, etc). What is it about my code, below, that keeps these
browsers from playing the file? IE tries download it, FireFox plays a
second of it and then quits.
I'm actualy fine with the file downloading. But how can I force FireFox
to download this file? Am I missing some crucial header?
> > 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
> >
>
> ---
>
> $fileToPlay = "Enemy.mp3";
>
> $allBytesInFile = filesize($fileToPlay);
> $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;
>
> $streamToOpen = "www.monkeyclaus.org";
> $port = "80";
> $path = "/$fileToPlay";
>
> header("Content-type: audio/mpeg");
> $socket = fsockopen($streamToOpen,$port);
>
> fputs($socket, "GET $path HTTP/1.0\r\n");
> fputs($socket, "Host: $streamToOpen\r\n");
> fputs($socket, "Accept: */*\r\n");
> fputs($socket, "Connection: close\r\n\r\n");
>
> // while (!feof($socket)) {
> // $buffer = fgets($socket, 4096);
> // echo $buffer;
> // }
>
> $totalSize = 0;
> for ($i=0; $i < $tenPercentOfFileInBytes; ) {
> $buffer = fgets($socket);
> $strSize = strlen($buffer);
> $totalSize = $totalSize + $strSize;
> // echo "$strSize \n";
> $i = $i + $strSize;
> echo $buffer;
> }
>
> fclose($socket);
Navigation:
[Reply to this message]
|