MP3 Flash Player PHP readfile()缓冲区

时间:2015-01-24 09:49:56

标签: php buffer mp3 flash

我有一个mp3 flash播放器,它可以很好地显示歌曲的加载部分。

<embed src="player.swf" width="70" height="15" 
FlashVars="song=songs/song.mp3"/>

但现在我需要从.php文件加载歌曲,所以就像这样

<embed src="player.swf" width="70" height="15" FlashVars="song=song.php"/>

这是我的歌曲.php

$filename="songs/song.mp3";
header("Expires: -1");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Content-type: audio/mpeg");
header("Content-Transfer-Encoding: binary");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0");
$len = filesize($filename);
header("Content-Length: $len;\n");
$outname=$archivo;
header("Content-Disposition: application/octet-stream");

readfile($filename); 

它与播放/停止按钮完美配合,但问题在于它没有向我显示歌曲的加载部分。

1 个答案:

答案 0 :(得分:-1)

在搜索提示/代码/答案几个小时后,我找到了Anindya的代码并由Mihai Iorga编辑,最终为我工作,请查看问题here。代码:

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);

所以我刚刚在song.php中替换了这段代码,现在它完美无缺!