我想从动态链接播放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
谢谢
最佳答案
如果仅运行PHP脚本,则浏览器应能够立即下载MP3文件。
如果这不起作用,则说明您的PHP脚本存在一些问题。
关于php - HTML5音频元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18426512/