Skip to content

Instantly share code, notes, and snippets.

@cvan
Last active February 23, 2019 12:24
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cvan/553c76a28007717349c480da6968d7f6 to your computer and use it in GitHub Desktop.
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
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');
@jamess922
Copy link

Hi : I would like to use your code with AR.js but not working ,so is that possible ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment