Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony return video in controller

I want to do some filters about user and permision to video and I do a route:

app_filter_f:
    path: /products/{idProduct}/movies/{name}.mp4
    defaults: { _controller: AppBundle:App:filterRequest }

and a controler with a action similar with https://creativcoders.wordpress.com/2014/05/12/symfony2-how-to-send-video-response-to-twig-view/ with filesystem https://github.com/KnpLabs/KnpGaufretteBundle

return new \Symfony\Component\HttpFoundation\Response($fs->read('14/movies/session1_ch1.mp4'),200,[
                'Content-Type' => 'video/mp4',
                'Connection' => 'close',
                'Content-Length' => $fs->size('14/movies/session1_ch1.mp4')
            ]);

the problem is my video is load in page, but i cant go to a next minute, only can go back, but ahead not.

on frontend I used html5:

<video id="course-video" width="100%" controls>
    <source src="{{ course.modules.first.movies.isEmpty() ? '' :course.modules.first.movies.first().downloadPath }}" type="video/mp4">
    Your browser does not support HTML5 video.
</video>

I was try to find any solution with that but I don't found, is posible to simulate a returned video with symfony, and work to change minute ahead and back ?

like image 857
Laurentiu Avatar asked Nov 26 '25 13:11

Laurentiu


1 Answers

// use Symfony\Component\HttpFoundation\BinaryFileResponse

$response = new BinaryFileResponse($webPath);
$response->setAutoEtag(true);
$response->headers->set('Content-Type', 'video/mp4');
return $response;
like image 112
fabpico Avatar answered Nov 29 '25 02:11

fabpico



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!