Last active
February 23, 2019 12:24
-
-
Save cvan/553c76a28007717349c480da6968d7f6 to your computer and use it in GitHub Desktop.
handle autoplay of <video> in A-Frame on mobile (iOS, Android) - see https://github.com/aframevr/aframe/pull/2657/files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
Hi : I would like to use your code with AR.js but not working ,so is that possible ?