簡體   English   中英

HTML5音頻元素

[英]HTML5 Audio element

我想從動態鏈接播放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

謝謝

如果僅運行PHP腳本,則瀏覽器應能夠立即下載MP3文件。

如果這不起作用,則說明您的PHP腳本存在一些問題。

您只應在PHP中指定一個Content-Type 您不能只發送逗號分隔列表AFAIK。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM