diff options
author | flashk <flashk@ampache> | 2007-12-26 18:00:22 +0000 |
---|---|---|
committer | flashk <flashk@ampache> | 2007-12-26 18:00:22 +0000 |
commit | 983983592734af9054e4e5fc26665bd5a0d7d264 (patch) | |
tree | e74cc2ec82ec26de266393c37ebbc411b1268088 /play | |
parent | dab6c4d46d52f6436077f6d842016c0110e69129 (diff) | |
download | ampache-983983592734af9054e4e5fc26665bd5a0d7d264.tar.gz ampache-983983592734af9054e4e5fc26665bd5a0d7d264.tar.bz2 ampache-983983592734af9054e4e5fc26665bd5a0d7d264.zip |
Fix for proper byte range handling (necessary for iPhone support). Fixed streaming problem with Windows Media Player.
Diffstat (limited to 'play')
-rw-r--r-- | play/index.php | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/play/index.php b/play/index.php index 4995421e..38e6bcbf 100644 --- a/play/index.php +++ b/play/index.php @@ -265,22 +265,23 @@ else { // Put this song in the now_playing table Stream::insert_now_playing($song->id,$uid,$song->time,$sid); -if ($start) { - debug_event('seek','Content-Range header recieved, skipping ahead ' . $start . ' bytes out of ' . $song->size,'5'); - $browser->downloadHeaders($song_name, $song->mime, false, $song->size); - fseek( $fp, $start ); - $range = $start ."-". ($song->size-1) . "/" . $song->size; - header("HTTP/1.1 206 Partial Content"); - header("Content-Range: bytes=$range"); +if (isset($start)) { // Calculate stream size from byte range if(isset($end)) { $end = min($end,$song->size-1); - $stream_size = ($end-$start)+1; + $stream_size = ($end-$start)+1; } else { $stream_size = $song->size - $start; } + + debug_event('seek','Content-Range header recieved, skipping ahead ' . $start . ' bytes out of ' . $song->size,'5'); + $browser->downloadHeaders($song_name, $song->mime, false, $song->size); + fseek( $fp, $start ); + $range = $start ."-". $end . "/" . $song->size; + header("HTTP/1.1 206 Partial Content"); + header("Content-Range: bytes $range"); header("Content-Length: ".($stream_size)); } @@ -300,12 +301,17 @@ $bytes_streamed = 0; $min_bytes_streamed = $song->size / 2; // Actually do the streaming -do { - $buf = fread($fp, 2048); - print($buf); - $bytes_streamed += 2048; +do { + $buf = fread($fp, min(2048,$stream_size-$bytes_streamed)); + print($buf); + $bytes_streamed += strlen($buf); } while (!feof($fp) && (connection_status() == 0) AND $bytes_streamed < $stream_size); +// Need to make sure enough bytes were sent. Some players (Windows Media Player) won't work if specified content length is not sent. +if($bytes_streamed < $stream_size AND (connection_status() == 0)) { + print(str_repeat(' ',$stream_size - $bytes_streamed)); +} + // Make sure that a good chunk of the song has been played if ($bytes_streamed > $min_bytes_streamed) { debug_event('Stats','Registering stats for ' . $song->title,'5'); |