【问题标题】:HTML5 audio from PHP script来自 PHP 脚本的 HTML5 音频
【发布时间】:2015-12-17 17:30:17
【问题描述】:

我想播放由 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);

它可以播放,但我无法更改音频元素中的当前时间。范围滑块不起作用。

【问题讨论】:

标签: php html audio http-headers


【解决方案1】:

为了让搜索栏工作,它只是在标题中遗漏了一些东西。内容长度和接受范围。 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);

【讨论】:

    猜你喜欢
    • 2012-11-01
    • 1970-01-01
    • 2012-10-30
    • 2011-02-26
    • 2012-08-05
    • 1970-01-01
    • 2018-02-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多