Last Updated: November 20, 2017
· tomas2387

AutoPlay HLS videos

Due to recent autoplay policies, hls autoplaying is now pretty easy to do.

//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';