Closed jiang-yuan closed 2 years ago
There's no feature to add. You can achieve a similar effect as the linked demo with nothing more than than the autoload feature and the YouTube IFrame API. Off the cuff example that works about the same (you could tweak to your hearts content).
<script src="https://www.youtube.com/iframe_api" id="iframe-demo"></script>
<script type="module" src="../lite-youtube.js"></script>
<style>
#test-jsapi {
pointer-events: none;
}
</style>
<lite-youtube
id="test-jsapi"
videoid="WhY7uyc56ms"
autoload
params="autoplay=1&mute=1&loop=1&controls=0&modestbranding=1&playsinline=1&rel=0&enablejsapi=1"
></lite-youtube>
<script type="text/javascript">
let player;
function setupYT() {
player = new YT.Player(
document
.querySelector('#test-jsapi')
.shadowRoot.querySelector('iframe'),
{
events: {
onReady: onPlayerReady,
},
}
);
}
function onPlayerReady() {
player.playVideo();
}
document.addEventListener('liteYoutubeIframeLoaded', () => {
try {
setupYT();
} catch(e) {
// in case we're too fast
setTimeout(setupYT, 100);
}
}, false);
</script>
</body>
</html>
Thank you. I will try it.
Would you like to introduce an option with all the following features into your package? like auto loop play, removing controls. The demo and code: https://codepen.io/adamgreenough/pen/bGrgoNb?editors=1100