Skip to content

Commit d0fdd76

Browse files
Merge pull request #8 from seyed-me/fix/CONTENT_LENGTH_MISMATCH
fix ERR_CONTENT_LENGTH_MISMATCH on chromium based browsers
2 parents 7fd458a + af64ecc commit d0fdd76

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

src/VideoStreamer.php

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,6 @@ private function setHeader()
6464
$range = explode('-', $range);
6565
$c_start = $range[0];
6666

67-
if (isset($range[1]) && is_numeric($range[1])) {
68-
\Log::info('$range:'.$range[1].gettype($range[1]));
69-
} else {
70-
\Log::info('default: '.$c_end);
71-
}
72-
7367
$c_end = (isset($range[1]) && is_numeric($range[1])) ? $range[1] : $c_end;
7468
}
7569
$c_end = ($c_end > $this->end) ? $this->end : $c_end;
@@ -83,8 +77,17 @@ private function setHeader()
8377
$length = $this->end - $this->start + 1;
8478
fseek($this->stream, $this->start);
8579
header('HTTP/1.1 206 Partial Content');
86-
header('Content-Length: '.$length);
87-
header("Content-Range: bytes $this->start-$this->end/".$this->size);
80+
header('Content-Length: ' . $length);
81+
header("Content-Range: bytes $this->start-$this->end/" . $this->size);
82+
}
83+
84+
/**
85+
* close curretly opened stream
86+
*/
87+
private function end()
88+
{
89+
fclose($this->stream);
90+
exit;
8891
}
8992

9093
/**
@@ -94,8 +97,7 @@ private function stream()
9497
{
9598
$i = $this->start;
9699
set_time_limit(0);
97-
$readBytes = 0;
98-
while (! feof($this->stream) && ($i <= $this->end) && ($readBytes < ($this->buffer * 4))) {
100+
while (!feof($this->stream) && $i <= $this->end) {
99101
$bytesToRead = $this->buffer;
100102
if (($i + $bytesToRead) > $this->end) {
101103
$bytesToRead = $this->end - $i + 1;
@@ -104,7 +106,6 @@ private function stream()
104106
echo $data;
105107
flush();
106108
$i += $bytesToRead;
107-
$readBytes += $bytesToRead;
108109
}
109110
}
110111

@@ -115,12 +116,7 @@ public function start()
115116
{
116117
$this->setHeader();
117118
$this->stream();
118-
119-
/**
120-
* close curretly opened stream.
121-
*/
122-
fclose($this->stream);
123-
exit;
119+
$this->end();
124120
}
125121

126122
public static function streamFile($path)

0 commit comments

Comments
 (0)