如果输出由PHP脚本提供,则播放时jPlayer不会缓存媒体

如果输出由PHP脚本提供,则播放时jPlayer不会缓存媒体,php,jquery,jplayer,Php,Jquery,Jplayer,换句话说:它不会在播放歌曲时缓存歌曲的其余部分 JS: PHP(getogg.PHP): 但是,直接链接工作正常,歌曲正在缓存: 奥加:'http://mysite/oggs/1234.ogg" 请帮助解决此问题。尝试以下操作: <?php error_reporting(E_ALL); $status=stream("./oggs/1234.ogg"); if($status !== true){ if($status=='1'){echo('Cannot stream

换句话说:它不会在播放歌曲时缓存歌曲的其余部分

JS:

PHP(getogg.PHP):


但是,直接链接工作正常,歌曲正在缓存: 奥加:'http://mysite/oggs/1234.ogg"

请帮助解决此问题。

尝试以下操作:

<?php
error_reporting(E_ALL);

$status=stream("./oggs/1234.ogg");

if($status !== true){
    if($status=='1'){echo('Cannot stream a folder check path!');}
    if($status=='2'){echo('File not found!');}
}

function stream($file,$speed=1024){
    if (file_exists($file)) {
        if(is_dir($file)){return '1';}
        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename="'.basename($file).'"');
        header('Content-Transfer-Encoding: binary');
        header('Connection: Keep-Alive');
        header('Expires: 0');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Pragma: public');
        header('Content-Length: '.sprintf("%u", filesize($file)));

        ob_clean();
        $handle = fopen($file, "rb");
        $chunksize=(sprintf("%u", filesize($file))/$speed);

        set_time_limit(0);
        while (!feof($handle)) {
            echo fgets($handle, $chunksize);
            flush();
        }
        fclose($handle);
        return true;
    }else{
        return '2';
    }
    return;
}
?>
试试这个:

<?php
error_reporting(E_ALL);

$status=stream("./oggs/1234.ogg");

if($status !== true){
    if($status=='1'){echo('Cannot stream a folder check path!');}
    if($status=='2'){echo('File not found!');}
}

function stream($file,$speed=1024){
    if (file_exists($file)) {
        if(is_dir($file)){return '1';}
        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename="'.basename($file).'"');
        header('Content-Transfer-Encoding: binary');
        header('Connection: Keep-Alive');
        header('Expires: 0');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Pragma: public');
        header('Content-Length: '.sprintf("%u", filesize($file)));

        ob_clean();
        $handle = fopen($file, "rb");
        $chunksize=(sprintf("%u", filesize($file))/$speed);

        set_time_limit(0);
        while (!feof($handle)) {
            echo fgets($handle, $chunksize);
            flush();
        }
        fclose($handle);
        return true;
    }else{
        return '2';
    }
    return;
}
?>

该问题与OGG格式有关。

将媒体更改为MP3修复了一个问题。

该问题与OGG格式有关。
将媒体更改为MP3解决了一个问题。

您的意思是渐进式缓冲吗?另外,像这样吐出整个文件可能会导致问题,更不用说高内存使用率了。您应该设置正确的缓存头,用fgets吐出较小的块,并清除buffer@LawrenceCherone:听起来很合理,你能举个例子吗?你是说渐进式缓冲吗?另外,像这样吐出整个文件可能会导致问题,更不用说高内存使用率了。您应该设置正确的缓存头,用fgets吐出较小的块,并清除buffer@LawrenceCherone:听起来很合理,你能提供一个例子吗?@Radio好的,现在试试,直接访问脚本sorry,浏览器故障,重新启动,找不到文件,忘记它是Windows,需要“../”而不是“/”。浏览器正在获取流,可以在VLC和Winamp中播放,但不能在jPlayer中播放。@广播ok,立即尝试,直接访问脚本Sorry,浏览器出现故障,重新启动,找不到文件,忘记它是Windows,需要“../”而不是“../”。浏览器正在获取流,可以在VLC和Winamp中播放,但不能在jPlayer中播放。
<?php
error_reporting(E_ALL);

$status=stream("./oggs/1234.ogg");

if($status !== true){
    if($status=='1'){echo('Cannot stream a folder check path!');}
    if($status=='2'){echo('File not found!');}
}

function stream($file,$speed=1024){
    if (file_exists($file)) {
        if(is_dir($file)){return '1';}
        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename="'.basename($file).'"');
        header('Content-Transfer-Encoding: binary');
        header('Connection: Keep-Alive');
        header('Expires: 0');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Pragma: public');
        header('Content-Length: '.sprintf("%u", filesize($file)));

        ob_clean();
        $handle = fopen($file, "rb");
        $chunksize=(sprintf("%u", filesize($file))/$speed);

        set_time_limit(0);
        while (!feof($handle)) {
            echo fgets($handle, $chunksize);
            flush();
        }
        fclose($handle);
        return true;
    }else{
        return '2';
    }
    return;
}
?>