我正在使用soundmanager2,我遇到Safari问题。
我成功地将受保护的文件(在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文件流之间似乎存在问题。
任何?想要修复/解决这个问题吗?
答案 0 :(得分:5)
您需要支持字节范围请求。 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