gpt4 book ai didi

php - Soundmanager2、Safari 和 PHP 流式传输错误

转载 作者:行者123 更新时间:2023-12-02 21:54:11 24 4
gpt4 key购买 nike

我正在使用 soundmanager2,但 Safari 遇到问题。

我成功地将 protected 文件(在 webroot 之外)从 PHP 流式传输到 Soundmanager2,使用如下内容:

//check if user is logged in and has rights on $file
//if yes stream file

if (file_exists($file)) {
$filepath = $file;
$filesize = filesize($filepath);

header("Pragma: no-cache");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header('Content-Disposition: attachment;filename="'.$filename.'"');
header("Content-Transfer-Encoding: binary");
header('Content-Type: audio/mpeg');
header('Content-Length: '.$filesize);
@readfile($filepath);
exit(0);
}

这在 Firefox 和 Chrome 上运行良好,mp3 文件正在播放,但在 Safari 中我得到:

soundmanager2.js:1190basicMP3Sound0: Using HTML5
soundmanager2.js:1190basicMP3Sound0: play(): Attempting to load
soundmanager2.js:1190basicMP3Sound0: load (/privateaccess/index/1415)
soundmanager2.js:1190basicMP3Sound0: waiting
soundmanager2.js:1190basicMP3Sound0: loadstart
soundmanager2.js:1190basicMP3Sound0: loadedmetadata
soundmanager2.js:1190basicMP3Sound0: HTML5 error, code 3
soundmanager2.js:1188basicMP3Sound0: Failed to load / invalid sound? Zero-length duration reported. (/privateaccess/index/1415)

只有当我从 PHP 流式传输文件时,我才会收到此错误,它正在处理 webroot 中的文件(由 apache 而不是 PHP 提供)。

如果我直接点击 www.myurl.com/privateaccess/index/1415,文件就会被下载,所以这看起来确实是 Safari、Soundmanager2 和 PHP 文件流之间的问题。

有人吗?有解决/解决这个问题的想法吗?

最佳答案

您需要支持字节范围请求。 See SoundManager2's Technical Notes on the subject.

示例请求:

GET some.ogg HTTP/1.1
Range: bytes=5210604-5275910

预期响应:

HTTP/1.1 206 Partial Content
Accept-Ranges: bytes
Content-length: 65307
Content-Range: bytes 5210604-5275910/5275911
Content-Type: audio/ogg

关于php - Soundmanager2、Safari 和 PHP 流式传输错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18053677/

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