Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
handle autoplay of <video> in A-Frame on mobile (iOS, Android) - see https://github.com/aframevr/aframe/pull/2657/files
function playVideoOnClick (selector) {
el = document.querySelector(selector);
if (el) {
addListener();
} else {
window.addEventListener('load', addListener);
}
function addListener () {
if (el.paused) {
window.addEventListener('click', handleFirstClick);
}
function handleFirstClick () {
try {
if (el.muted) {
delete el.muted;
}
if (el.paused) {
el.play();
}
} catch (e) {
}
removeHandleFirstClick();
}
function removeHandleFirstClick () {
window.removeEventListener('click', handleFirstClick);
}
}
}
playVideoOnClick('video');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment