doupa8922 2013-08-25 06:53 采纳率: 100%
浏览 56

HTML5音频元素

I want to play from dynamic link for MP3

I am using this code to send mp3 instead of direct link :

PHP Side :

$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 side :

<audio controls>
    <source src="http://localhost/music.php" type="audio/mpeg"  preload="auto">
    Your browser does not support the audio element.
</audio>

But the Browser can not play that , I have no problem with WAV file , but for mp3 , it does not work

there is no problem if I use direct link instead of php script , so my browser can support MP3

thanks

  • 写回答

2条回答 默认 最新

  • dpz90118 2013-08-25 07:33
    关注

    If you run PHP script alone your browser should be able to download the MP3 file immediately.

    if this is not working then there is a some problem in ur PHP Script.

    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改