Streaming mp3 file through php

前端 未结 3 1456
太阳男子
太阳男子 2020-12-31 20:39

Here is my php code to stream mp3 file through php

set_time_limit(0);
$dirPath = \"path_of_the_directory\";
$songCode = $_REQUEST[\'c\'];
$filePath = $dirPat         


        
3条回答
  •  难免孤独
    2020-12-31 20:50

    array(
             'method'=>'GET',
             'header'=>"Accept-language: en\r\n"
             )
         )
     );
    
    
     header('Content-type: audio/mpeg');
     header ("Content-Transfer-Encoding: binary");
     header ("Pragma: no-cache");
     header ("icy-br: " . $bitrate);
    
     $fpOrigin=fopen($filePath, 'rb', false, $strContext);
     while(!feof($fpOrigin)){
       $buffer=fread($fpOrigin, 4096);
       echo $buffer;
       flush();
     }
     fclose($fpOrigin);
    

    I know this post was from last year but someone might find this useful. This will stream the content.

提交回复
热议问题