(function() {
const video = document.querySelector(‘#video-auto’);
if (!video) return;
video.muted = true;
video.loop = true;
video.setAttribute(‘playsinline’, »);
video.setAttribute(‘webkit-playsinline’, »);
video.setAttribute(‘x5-playsinline’, »);
const tryPlay = () => video.play().catch(()=>{});
// relancer dès que la vidéo peut être jouée
video.addEventListener(‘canplay’, tryPlay);
video.addEventListener(‘canplaythrough’, tryPlay);
tryPlay();
// relance si pause
video.addEventListener(‘pause’, () => setTimeout(tryPlay, 50));
// overlay invisible pour intercepter les touch events
const container = document.querySelector(‘#video-container’);
const overlay = document.createElement(‘div’);
overlay.style.position = ‘absolute’;
overlay.style.top = ‘0’;
overlay.style.left = ‘0’;
overlay.style.width = ‘100%’;
overlay.style.height = ‘100%’;
overlay.style.zIndex = ’10’;
overlay.style.background = ‘transparent’;
overlay.style.touchAction = ‘pan-y’;
container.appendChild(overlay);
[‘touchstart’,’touchend’,’click’].forEach(evt => {
overlay.addEventListener(evt, e => { e.stopPropagation(); tryPlay(); }, {passive:true});
});
})();