private function getStreamResponse(Extra $extra, string $aspect = '16x9') { $size = \Storage::size($path = $this->getVideoPath($extra->id, $aspect)); return response()->download($path, 'test123', ['Content-Type' => 'video/mp4']); $stream = fopen($path, "r"); $type = 'video/mp4'; $start = 0; $length = $size; $status = 200; $headers = ['Content-Type' => $type, 'Content-Length' => $size, 'Accept-Ranges' => 'bytes']; if (false !== ($range = request()->server('HTTP_RANGE', false))) { list($param, $range) = explode('=', $range); if (strtolower(trim($param)) !== 'bytes') { header('HTTP/1.1 400 Invalid Request'); exit; } list($from, $to) = explode('-', $range); if ($from === '') { $end = $size - 1; $start = $end - intval($from); } elseif ($to === '') { $start = intval($from); $end = $size - 1; } else { $start = intval($from); $end = intval($to); } $length = $end - $start + 1; $status = 206; $headers['Content-Range'] = sprintf('bytes %d-%d/%d', $start, $end, $size); } return response()->stream(function () use($stream, $start, $length) { fseek($stream, $start, SEEK_SET); echo fread($stream, $length); fclose($stream); }, $status, $headers); }
<th>ACCION</th> </tr> </thead> <tbody> @foreach($medios as $medio) <tr> <td>{{ $medio->id }}</td> <td> <a href="/medios/{{ $medio->nombre}}" target="newwindow" data-toggle="tooltip" data-placement="right" title="PRESIONE CLICK PARA VER O DESCARGAR SEGUN SEA EL TIPO DE ARCHIVO"> <?php if (Storage::exists($medio->nombre)) { $nombre = $medio->nombre; $tamanio = Storage::size($medio->nombre); $creado = $medio->created_at; $tipo = $medio->tipo; if ($tipo == 'jpg' || $tipo == 'png' || $tipo == 'jpeg' || $tipo == 'gif') { ?> <img class="img_click" src="/medios/{{ $medio->nombre}}"><?php } else { if ($tipo == 'pdf') { ?> <img class="img_click" src="/img/pdf.png"><?php } else { if ($tipo == 'doc' || $tipo == 'dot' || $tipo == 'docx') { ?> <img class="img_click" src="/img/m_word.png"><?php } else { if ($tipo == 'xls' || $tipo == 'xlm' || $tipo == 'xlt' || $tipo == 'xlv' || $tipo == 'ods') {
/** * to stream videos online */ public function streamVideo() { $size = \Storage::size($this->getRealPath($this->filepath)); $file = \Storage::get($this->getRealPath($this->filepath)); $stream = fopen($this->getRealPath($this->filepath), "r"); $type = 'video/mp4'; $start = 0; $length = $size; $status = 200; $headers = ['Content-Type' => $type, 'Content-Length' => $size, 'Accept-Ranges' => 'bytes']; if (false !== ($range = request()->server('HTTP_RANGE', false))) { list($param, $range) = explode('=', $range); if (strtolower(trim($param)) !== 'bytes') { header('HTTP/1.1 400 Invalid Request'); exit; } list($from, $to) = explode('-', $range); if ($from === '') { $end = $size - 1; $start = $end - intval($from); } elseif ($to === '') { $start = intval($from); $end = $size - 1; } else { $start = intval($from); $end = intval($to); } $length = $end - $start + 1; $status = 206; $headers['Content-Range'] = sprintf('bytes %d-%d/%d', $start, $end, $size); } return response()->stream(function () use($stream, $start, $length) { fseek($stream, $start, SEEK_SET); echo fread($stream, $length); fclose($stream); }, $status, $headers); // dd($this->getRealPath($this->filepath)); // $video = new StreamVideoJob($this->getRealPath($this->filepath)); // $video->start(); // exit; }