How to stream a video in Laravel

68 Views Asked by At

I'm trying to stream a video in Laravel 9 by using imanghafoori1/laravel-video package. but I keep getting an error message:

fopen(C:...\storage\videoFiles/ui/2024-02-11-1-I6bnWsI8J0-128210 (Original).mp4): Failed to open stream: No such file or directory

I have added the route =>

Route::get('/stream/{video}', [VideoController::class, 'stream'])->name('admin.product.video.stream');

and the method in controller =>

public function stream(Video $video)
    {
      $path = storage_path($video->file_path);
      VideoStreamer::streamFile($path);
    }

also the link in my blade =>

<a href="{{ route('admin.product.video.stream', $video->id) }}" >play</a>

How can I fix the problem?

1

There are 1 best solutions below

0
Laravel Learner On

I used Storage::path to access the file_path of my video. here is the stream function:

public function stream(Video $video)
    {
      $path = Storage::path($video->file_path);
      VideoStreamer::streamFile($path);
    }