jPlayer не кэширует мультимедиа во время воспроизведения, если вывод предоставляется PHP-скриптом - PullRequest
1 голос
/ 03 апреля 2012

Другими словами: он не кэширует оставшуюся часть песни во время воспроизведения.

JS:

$('#jplayer-9999').jPlayer({
    ready: function() {
        $(this).jPlayer('setMedia', {
            oga: 'http://mysite/getogg.php',
        }).jPlayer('play', 15);

        $(this).bind($.jPlayer.event.timeupdate, function(event) {
            if(event.jPlayer.status.currentTime > 55) {
                $(this).jPlayer('play', 15);
            }
        });

    },
    play: function() {
        $(this).jPlayer('pauseOthers');
    },
    cssSelectorAncestor: '#jp_container_9999',
    swfPath: '/js/jplayer',
    supplied: 'oga',
    preload: 'auto'
});

PHP (getogg.php):

<?php

header('Content-type: audio/ogg');
$output = readfile("/oggs/1234.ogg");

echo $output;

?>

Однако прямые ссылки работают нормально, и песня кешируется: oga: 'http://mysite/oggs/1234.ogg'

Пожалуйста, помогите решить эту проблему.

Ответы [ 2 ]

1 голос
/ 03 апреля 2012

Попробуйте:

<?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;
}
?>
0 голосов
/ 03 апреля 2012

Проблема была связана с форматом OGG.Смена носителя на MP3 исправила проблему.

...