【问题标题】:HTML5 Audio elementHTML5 音频元素
【发布时间】: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


【解决方案1】:

如果您单独运行 PHP 脚本,您的浏览器应该能够立即下载 MP3 文件。

如果这不起作用,那么您的 PHP 脚本中存在一些问题。

【讨论】:

    【解决方案2】:

    您应该只在您的 PHP 中指定一个 Content-Type。您不能只发送逗号分隔的列表 AFAIK。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-16
      • 1970-01-01
      • 2014-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-04
      相关资源
      最近更新 更多