换句话说:它在播放时不会缓存其余歌曲。
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:&#39; http://mysite/oggs/1234.ogg'
请帮助解决此问题。
答案 0 :(得分:1)
试试这个:
<?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;
}
?>
答案 1 :(得分:0)
该问题与OGG格式有关。 将媒体更改为MP3修复了一个问题。