2017-11-06 11 views
-1

私は現在、このPHPからHTML5オーディオタグにストリームし、オーディオをシーク可能にする簡単な方法は?

<audio id ="player"> 
    <source src="includes/playsong.php" id = "player"> 
</audio> 

JS

var playsong = function (songName) { 
    $('#playing').html(songName); 
    if (currentSong === songName) { 
     return; 
    } 
    $.post('includes/songrequest.php', {'request': songName}, function() { 
     $('#source').attr("src", "includes/playsong.php/" + songName); 
     player.load(); 
     play(); 
    }); 

$('#slider').slider({ 
    min: 0, 
    max: 1, 
    step: 0.001, 
    change: function (event, ui) { 
     player.currentTime = player.duration * ui.value; 

     } 
} 

そしてPHPユーザが実際にパスを使って曲を所有している場合、PHPは、テーブルから曲の位置を取得します

$file = mysqli_fetch_assoc($song)['location']; 
header('Content-Type: audio/' . pathinfo($file, PATHINFO_EXTENSION)); 
header('Content-Length: ' . filesize($file)); 
header('Content-Transfer-Encoding: binary'); 
header('Accept-Ranges: bytes'); 
header('Cache-Control: no-cache'); 
readfile($file); 

を持っています。コードは現在、範囲を許可していても、トラック全体を再生する前にロードするか、トラックをスキップするまで、ファイル全体がロードされるのを待っています。すべてのことを待たずに正しいチャンクを送る別の方法はありますか?

答えて

-1

手作業でファイルを出力しようとしたことがありますか?

set_time_limit(0); 
$file = @fopen($file_path,"rb"); 
while(!feof($file)) { 
    print(@fread($file, 1024*8)); 
    ob_flush(); 
    flush(); 
} 

このコードスニペットはhttp://www.media-division.com/the-right-way-to-handle-file-downloads-in-php/です。欲しいのですが。

+0

あなたは '@'を使って打たれるべきです。 –

+0

これはとてもうまくいくようです。 –

関連する問題