hatemjapo
hatemjapo

Reputation: 840

laravel 9 return video chrome no rewind

i am using laravel ver 9 and i am trying to play a video from the storage.

I managed to read and return the video. The problem i have is that in chrome, sometimes the video is not loading and fast forward and rewind is not working. In Firefox everything is working fine.

I have been playing with it for quite a while but cant get it to work in chrome. Sometimes it works and when i refresh, its not working anymore. Sometimes the video loads, sometimes not...

This is my function to load the video i tried to give status Code 206. I tried to change the length and range, with no real success... Thats actually the information that chrome reads if i change the soruce directly to the video.

    function getVideo() {
    $video = Storage::disk('local')->get("user/All/video.mp4");
    $response = Response::make($video, 200);
    $response->header('Content-Type', 'video/mp4');
    // $response->header('Accept-Ranges', 'bytes');
    // $response->header('Content-Length', '65536');
    // $response->header('content-range', 'bytes 0-65535/788493');
    return $response;
}

this is the video tag, its getting the source via route

<video id="my-video" class="video-js vjs-default-skin vjs-16-9 vjs-big-play-centered" controls
            preload="auto" poster="" data-setup="{}">
            <source src="{{route('/get-video')}}" type='video/mp4'>
            <p class="vjs-no-js">
                To view this video please enable JavaScript, and consider upgrading to a web browser that
                <a href="https://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a>
            </p>
        </video>

the video i am playing with is 771Kb and has a duration of 10sec

What am i missing or what should i pass so chrome can always play the video and allow rewind and fast forward?

Upvotes: 0

Views: 704

Answers (1)

Greg Machiavelli
Greg Machiavelli

Reputation: 11

I solved this issue by replacing the Response::make() method with file()

return response()->file(storage_path(). '/app/private/'. $fileName);

Upvotes: 1

Related Questions