justinribeiro / lite-youtube

The fastest little YouTube web component on this side of the internet. The shadow dom web component version of Paul's lite-youtube-embed.
https://www.npmjs.com/package/@justinribeiro/lite-youtube
MIT License
836 stars 63 forks source link

Autoplay #66

Open brmassa opened 2 years ago

brmassa commented 2 years ago

I tried to add params="autoplay=1" to allow auto play (also autoload to start to play once it is on screen)

however, it does not work. It's because the plugin automatically includes autoplay=0 on all urls.

solution either: 1 not include autoplay=0 on video url 2 flag this behaviour

justinribeiro commented 2 years ago

Autoplay is a double edged sword. The flag doesn't work on mobile (because the web platform long ago agreed that was a bad idea) and setting autoplay=1 usually just results in desktop working which confuses integrators of the component who want the behavior on both platforms. On the other edge of the sword, the component uses that flag to create some of the injector behavior so you end up with a fast and smooth experience when clicking play.

To autoplay on both platforms you have to use the JS API and do some work like in the https://github.com/justinribeiro/lite-youtube/blob/main/demo/bg-play.html example or via the the iframe postMessage ala https://github.com/justinribeiro/lite-youtube/pull/67/commits/9af7a6f4fd208c44245042bcb60a73ce88c8a5de#diff-c2f0c4bb74f062c99d3589cb43e6820a4cfb7f8cad9432505b663c06132fb384R374-R379

I'll make a revision to the documentation that points this out in the interim, as I'll have to give this some thought in terms of something more turn key.