gpt4 book ai didi

php - 从 php 流式传输到 HTML5 音频标签并允许音频可搜索的简单方法?

转载 作者:行者123 更新时间:2023-12-03 02:34:51 26 4
gpt4 key购买 nike

我目前有这个

<audio id ="player">
<source src="includes/playsong.php" id = "player">
</audio>

JS
var playsong = function (songName) {
$('#playing').html(songName);
if (currentSong === songName) {
return;
}
$.post('includes/songrequest.php', {'request': songName}, function () {
$('#source').attr("src", "includes/playsong.php/" + songName);
player.load();
play();
});

$('#slider').slider({
min: 0,
max: 1,
step: 0.001,
change: function (event, ui) {
player.currentTime = player.duration * ui.value;

}
}

和 PHP
$file = mysqli_fetch_assoc($song)['location'];
header('Content-Type: audio/' . pathinfo($file, PATHINFO_EXTENSION));
header('Content-Length: ' . filesize($file));
header('Content-Transfer-Encoding: binary');
header('Accept-Ranges: bytes');
header('Cache-Control: no-cache');
readfile($file);

如果用户使用路径实际拥有歌曲,则 php 从表中获取歌曲位置。尽管我允许范围,但代码当前正在等待整个文件加载,然后再播放甚至跳过轨道。有没有另一种方法来发送正确的 block 而不等待整个事情?

最佳答案

也许尝试手动输出文件 block ?

set_time_limit(0);
$file = @fopen($file_path,"rb");
while(!feof($file)) {
print(@fread($file, 1024*8));
ob_flush();
flush();
}

我在这里找到了这个代码片段 http://www.media-division.com/the-right-way-to-handle-file-downloads-in-php/ .希望能帮助到你

关于php - 从 php 流式传输到 HTML5 音频标签并允许音频可搜索的简单方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47143802/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com