我想播放将从 php 脚本生成的音频。
客户端:
<audio controls autoplay src="audio.php"></audio>
服务器端:
$path = 'somefile.mp3';
header('Content-Type: audio/mpeg');
header('Cache-Control: no-cache');
header("Content-Transfer-Encoding: binary");
readfile($path);
可以播放,但我无法更改音频元素中的当前时间。范围 slider 不起作用。
最佳答案
为了使搜索栏正常工作,它只是在标题中缺少一些内容。内容长度和接受范围。 HTML 音频播放器需要它们来构建播放器搜索栏。
试试这个:
$path = 'somefile.mp3';
header('Content-Type: audio/mpeg');
header('Cache-Control: no-cache');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($path));
header('Accept-Ranges: bytes');
readfile($path);
关于php - 来自 PHP 脚本的 HTML5 音频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32688041/