Last Updated: October 24, 2021
·
8.98K
· Tomás Prado

AutoPlay HLS videos

Due to recent autoplay policies, hls autoplaying is now pretty easy to do.
https://webkit.org/blog/7734/auto-play-policy-changes-for-macos/

//We listen when we can play our video hls
video.addEventListener('canplaythrough', function () {
            var promise = video.play();
            if (promise !== undefined) {
                promise.catch(function(error) {
                    console.error('Auto-play was prevented');
                    console.error('We Show a UI element to let the user manually start playback');
                    buttonPlay.style.display = 'block';
                }).then(function() {
                    console.info('Auto-play started');
                    buttonPlay.style.display = 'none';
                });
            }
}); //  Fires when the browser can play through the audio/video without stopping for buffering

video.muted = 'muted';
video.autoplay = 'autoplay';
video.playsinline = 'true';