Friday, 15 June 2012

Streaming mp3 file through php -



Streaming mp3 file through php -

here php code stream mp3 file through php

set_time_limit(0); $dirpath = "path_of_the_directory"; $songcode = $_request['c']; $filepath = $dirpath . "/" . $songcode . ".mp3"; $strcontext=stream_context_create( array( 'http'=>array( 'method'=>'get', 'header'=>"accept-language: en\r\n" ) ) ); $fporigin=fopen($filepath, 'rb', false, $strcontext); header('content-type: application/octet-stream'); while(!feof($fporigin)){ $buffer=fread($fporigin, 4096); echo $buffer; flush(); } fclose($fporigin);

it's working on mac mini , other pcs not working on ipad , iphone. streaming working on other smart phones. help appreciated.

thanks

why content-type: application/octet-stream if it's song? alter headers:

set_time_limit(0); $dirpath = "path_of_the_directory"; $songcode = $_request['c']; $filepath = $dirpath . "/" . $songcode . ".mp3"; $strcontext=stream_context_create( array( 'http'=>array( 'method'=>'get', 'header'=>"accept-language: en\r\n" ) ) ); $fporigin=fopen($filepath, 'rb', false, $strcontext); header('content-disposition: inline; filename="song.mp3"'); header('pragma: no-cache'); header('content-type: audio/mpeg'); header('content-length: '.filesize($filepath)); while(!feof($fporigin)){ $buffer=fread($fporigin, 4096); echo $buffer; flush(); } fclose($fporigin);

le: removed content-transfer-encoding , changed content-disposition attachment inline

php streaming

No comments:

Post a Comment