Skip to content

Commit

Permalink
Merge pull request #3 from imanghafoori1/analysis-RvYx4M
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
imanghafoori1 authored Feb 15, 2020
2 parents 141b57e + bca1014 commit 499aad6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
1 change: 1 addition & 0 deletions src/StreamServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function register()
Response::macro('streamVideoFile', function ($filePath) {
return response()->stream(function () use ($filePath) {
$stream = new VideoStreamer($filePath);

return $stream->start();
});
});
Expand Down
37 changes: 16 additions & 21 deletions src/VideoStreamer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

class VideoStreamer
{
private $path = "";
private $path = '';

private $stream = "";
private $stream = '';

private $buffer = 102400;

Expand All @@ -16,7 +16,7 @@ class VideoStreamer

private $size = 0;

private $mime = "";
private $mime = '';

public function __construct($filePath = '')
{
Expand All @@ -26,8 +26,7 @@ public function __construct($filePath = '')
}

/**
* Open stream
*
* Open stream.
*/
private function open()
{
Expand All @@ -37,23 +36,22 @@ private function open()
}

/**
* Set proper header to serve the video content
*
* Set proper header to serve the video content.
*/
private function setHeader()
{
ob_get_clean();
header("Content-Type: " . $this->mime);
header("Cache-Control: max-age=2592000, public");
header("Expires: " . gmdate('D, d M Y H:i:s', time() + 2592000) . ' GMT');
header("Last-Modified: " . gmdate('D, d M Y H:i:s', @filemtime($this->path)) . ' GMT');
header('Content-Type: '.$this->mime);
header('Cache-Control: max-age=2592000, public');
header('Expires: '.gmdate('D, d M Y H:i:s', time() + 2592000).' GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s', @filemtime($this->path)).' GMT');
$this->start = 0;
$this->size = filesize($this->path);
$this->end = $this->size - 1;
header("Accept-Ranges: 0-" . $this->end);
header('Accept-Ranges: 0-'.$this->end);

if (! isset($_SERVER['HTTP_RANGE'])) {
header("Content-Length: " . $this->size);
header('Content-Length: '.$this->size);

return;
}
Expand Down Expand Up @@ -89,13 +87,12 @@ private function setHeader()
$length = $this->end - $this->start + 1;
fseek($this->stream, $this->start);
header('HTTP/1.1 206 Partial Content');
header("Content-Length: " . $length);
header("Content-Range: bytes $this->start-$this->end/" . $this->size);
header('Content-Length: '.$length);
header("Content-Range: bytes $this->start-$this->end/".$this->size);
}

/**
* close curretly opened stream
*
* close curretly opened stream.
*/
private function end()
{
Expand All @@ -105,8 +102,7 @@ private function end()
}

/**
* perform the streaming of calculated range
*
* perform the streaming of calculated range.
*/
private function stream()
{
Expand All @@ -125,8 +121,7 @@ private function stream()
}

/**
* Start streaming video content
*
* Start streaming video content.
*/
public function start()
{
Expand Down

0 comments on commit 499aad6

Please sign in to comment.