简体   繁体   English

HTML5音频元素

[英]HTML5 Audio element

I want to play from dynamic link for MP3 我想从动态链接播放MP3

I am using this code to send mp3 instead of direct link : 我正在使用此代码发送mp3而不是直接链接:

PHP Side : 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 side : HMLL侧:

<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 但是浏览器无法播放,我对WAV文件没有问题,但是对于mp3,它不起作用

there is no problem if I use direct link instead of php script , so my browser can support MP3 如果我使用直接链接而不是php脚本没有问题,那么我的浏览器可以支持MP3

thanks 谢谢

If you run PHP script alone your browser should be able to download the MP3 file immediately. 如果仅运行PHP脚本,则浏览器应能够立即下载MP3文件。

if this is not working then there is a some problem in ur PHP Script. 如果这不起作用,则说明您的PHP脚本存在一些问题。

You should only be specifying a single Content-Type in your PHP. 您只应在PHP中指定一个Content-Type You can't just send a comma delimited list AFAIK. 您不能只发送逗号分隔列表AFAIK。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM