我正在使用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);
} 这在火狐和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文件流之间的问题。
有没有人?一个解决/解决这个问题的想法?
发布于 2013-08-06 04:38:20
您需要支持字节范围请求。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/ogghttps://stackoverflow.com/questions/18053677
复制相似问题