【发布时间】:2013-08-25 06:53:04
【问题描述】:
我想从动态链接播放 MP3
我正在使用此代码发送 mp3 而不是直接链接:
PHP端:
$filename = "jadi.mp3";
$mime_type = "audio/mpeg, audio/x-mpeg, audio/x-mpeg-3, audio/mpeg3";
if (is_file($filename)) {
header("Content-Type: {$mime_type}");
header('Content-length: ' . filesize($filename));
header("Content-Disposition: attachment;filename = jadi.mp3");
header('X-Pad: avoid browser bug');
header('Cache-Control: no-cache');
header("Content-Transfer-Encoding: binary");
$fd = fopen($filename, "r");
while (!feof($fd)) {
echo fread($fd, 1024 * 200);
}
fclose($fd);
exit();
}
HMLL 方面:
<audio controls>
<source src="http://localhost/music.php" type="audio/mpeg" preload="auto">
Your browser does not support the audio element.
</audio>
但是浏览器不能播放,我对WAV文件没有问题,但是对于mp3,它不起作用
如果我使用直接链接而不是php脚本没有问题,所以我的浏览器可以支持MP3
谢谢
【问题讨论】:
-
您确定您正在测试的浏览器支持
mp3吗?如果我没记错的话,Firefox 只能在装有 Firefox 21+ 的 Windows 上播放MP3音频。 -
我用的是chrome,可以播放mp3
-
一个活生生的例子会更容易调试。我现在看不到任何明显不正确的内容。
标签: php javascript html audio html5-audio