Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sajed-zarrinpour/8b157aed3efda29f422196c5e6997f21 to your computer and use it in GitHub Desktop.
Save sajed-zarrinpour/8b157aed3efda29f422196c5e6997f21 to your computer and use it in GitHub Desktop.
minimalistic video and audio streaming for laravel 5.8
@extend('layouts.app')
@section('content')
<video id="player" playsinline webkit-playsinline controls="controls"
preload="metadata" data-cast-title="your-title"
data-cast-description="your-description">
<source src="{{route('video-stream',[$your-model->stream_uri])}}" type="video/mp4">
</video>
<audio id="player2" preload="none" controls width="750"
data-cast-title="your-title"
data-cast-description="your-description"
data-cast-poster="your-poster">
<source src="{{route('audio-stream',[$yourmodel->stream_uri])}}"
type="audio/mp3"
title="your-title"
data-playlist-thumbnail="your thumbnail"
data-playlist-description="your-description">
</audio>
@endsection
<?php
/*
* Based on this answer : https://laracasts.com/discuss/channels/laravel/audio-streaming
* here is my solution for the summernote editor image upload.
* Notes :
***** Make sure you read laravel 5.8 Storage Documentation here :
https://laravel.com/docs/5.8/filesystem#the-public-disk,
https://laravel.com/docs/5.8/responses#file-responses
***** For Simplicity I used clusures, means that this is originally **routes/web.php** file!
***** there is also anotherway to do this explained at:
https://gist.github.com/vluzrmos/993d400739dd2e9aa47d
*/
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Storage;
//note that I implemented both video and audio in the same clusure , you have to split them into two function!!!!!
Route::get('/your-desired-uri-to-show-to-people/{the-actuall-filename}', function ($filename) {
$file = Storage::disk('local')->get('public/path-to-your-video/audio'."/".$filename);
/* maybe some function call here to deduce the mime type from file name? */
return (new Response($file, 200))
->header('Content-Type', 'video/mp4');
//->header('Content-Type', 'audio/mpeg'); // for audio
})->name('video/audio-stream');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment