laravel-ffmpeg icon indicating copy to clipboard operation
laravel-ffmpeg copied to clipboard

VideoJs fails to work with dynamicHLSPlaylist (VIDEOJS: ERROR: (CODE:3. MEDIA_ERR_DECODE))

Open AliBayat opened this issue 3 years ago • 2 comments

im trying to protect my videos using the dynamic Playlist. and the route that i have for it, works fine. upon manually entering the route in the browser, the playlist, keys and media parts are available .

but as soon as i put the playlist in the source tag of the player.. videojs gives me an error: VIDEOJS: ERROR: (CODE:3. MEDIA_ERR_DECODE) this happens while all the necessary data is loaded in the network tab.

any guides would be appreciated

AliBayat avatar Feb 02 '22 06:02 AliBayat

Please share your implementation of DynamicHLSPlaylist.

pascalbaljet avatar May 13 '22 07:05 pascalbaljet

@pascalbaljet thanks for the reply this is my implementation that works

return FFMpeg::dynamicHLSPlaylist()
    ->fromDisk('s3')
    ->open("{$playlist}")
    ->setKeyUrlResolver(function ($key) use ($path) {   
        return Storage::disk('s3')->temporaryUrl("{$path}/{$key}", now()->addMinutes(10));
    })
    ->setMediaUrlResolver(function ($mediaFilename) use ($path) {
        return Storage::disk('s3')->temporaryUrl("{$path}/{$mediaFilename}", now()->addMinutes(10));
    })
    ->setPlaylistUrlResolver(function ($playlistFilename) use ($path) {
        return URL::temporarySignedRoute(
            'video.playlist', now()->addMinutes(10), ['playlist' => urlencode("{$path}/$playlistFilename")]
        );            
    });

since i've posted this issue, i've been trying different approaches. i believe i found out where the problem is laying as you see in setKeyUrlResolver method i am giving the file location of the keys instead of using a route for that.. and it works.

but as soon as i replace it with a route ‍video.key that is responsible for returning the key.. i get CODE:3 error in browser this happens while i can manually access this route and get the keys, but it seems videojs fails to do that.

i've tried different codes for 'video.key' route:

return Storage::disk('secrets')->download($key);

and

return response()->download(
    Storage::disk('secrets')->path($key),
    null,
    ['Content-Type' => 'application/octet-stream']
);

but none seems to be working.

AliBayat avatar May 13 '22 08:05 AliBayat