2

我正在使用 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 文件流之间的问题。

任何人?解决/解决此问题的想法?

4

1 回答 1

5

您需要支持字节范围请求。请参阅 SoundManager2 的有关该主题的技术说明。

示例请求:

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
于 2013-08-05T20:38:19.970 回答