hugomyb / filament-media-action

Automatically display your media (video, audio, pdf, image, ...) with an action in Filament
https://filamentphp.com/plugins/hugomyb-media-action
MIT License
33 stars 5 forks source link

Fix intermittent autoplay blocking issue by adding preload control option #11

Closed waggos-root closed 1 week ago

waggos-root commented 2 weeks ago

Hello, I tested this plugin with autoplay() enabled; clicking the same action sometimes refuses to play, resulting in infinite spinning. In the browser console, it can be read "Autoplay failed or was blocked". I modified the following code to get more details about the issue:

mediaElement.play().catch((e) => {
    console.log(e):
    console.log('Autoplay failed or was blocked.');
});

Then it pointed me to https://developer.chrome.com/blog/play-request-was-interrupted.

To resume, I added a Promise to the code, but a simple preload="none" worked just fine, so I removed the Promise.

hugomyb commented 1 week ago

Hi, thanks for your pull request and your fix.

Could you just slightly modify the logic of the ->preloadNone() method, naming it ->preload() and passing a boolean as parameter, defaulting to true, so if we pass false as parameter we'll put preload=“none” in the view.

Thank you very much !

waggos-root commented 1 week ago

Hello, I made the changes according to your suggestion. I also added this piece of code to the view:

{{ $preload == false ? 'preload="none"' : '' }

So, the default behaviour is preload auto.

hugomyb commented 1 week ago

Thank you !

Merged in latest version : v31.1.1