Skip to content

Instantly share code, notes, and snippets.

@cclloyd
Last active December 30, 2017 02:46
Show Gist options
  • Save cclloyd/72b5939c99e19cd378dbd5159e2ae156 to your computer and use it in GitHub Desktop.
Save cclloyd/72b5939c99e19cd378dbd5159e2ae156 to your computer and use it in GitHub Desktop.
<?php
public function clipGetVideo($request, $response, $args) {
$clipid = $args['clipid'];
$clip = GameClip::where('id', $clipid)->first();
$fh = fopen($clip->File, 'rb');
$stream = new \Slim\Http\Stream($fh);
$file_size = filesize($clip->File);
$seek_end = (empty($seek_end)) ? ($file_size - 1) : min(abs(intval($seek_end)),($file_size - 1));
$seek_start = (empty($seek_start) || $seek_end < abs(intval($seek_start))) ? 0 : max(abs(intval($seek_start)),0);
$response = $response
->withBody($stream)
->withHeader('Content-type', 'video/mp4')
->withHeader('Content-length', filesize($clip->File))
->withHeader('Content-Range', sprintf("bytes %d-%d/%d", $seek_start, $seek_end, $file_size))
->withStatus(206);
return $response;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment