Skip to content
Snippets Groups Projects
Commit 0c16dd16 authored by Robert Long's avatar Robert Long
Browse files

Update audio-context-fix to work for in Chrome.

parent 5a8c9635
No related branches found
No related tags found
No related merge requests found
...@@ -17,7 +17,7 @@ import "aframe-billboard-component"; ...@@ -17,7 +17,7 @@ import "aframe-billboard-component";
import "aframe-rounded"; import "aframe-rounded";
import "webrtc-adapter"; import "webrtc-adapter";
import "aframe-slice9-component"; import "aframe-slice9-component";
import "./utils/ios-audio-context-fix"; import "./utils/audio-context-fix";
import trackpad_dpad4 from "./behaviours/trackpad-dpad4"; import trackpad_dpad4 from "./behaviours/trackpad-dpad4";
import joystick_dpad4 from "./behaviours/joystick-dpad4"; import joystick_dpad4 from "./behaviours/joystick-dpad4";
......
/**
* Mobile Safari and Chrome will start Audio contexts in a "suspended" state.
* A user interaction (touch/mouse event) is needed in order to resume the AudioContext.
*/
document.addEventListener("DOMContentLoaded", () => {
const ctx = THREE.AudioContext.getContext();
function resume() {
ctx.resume();
setTimeout(function() {
if (ctx.state === "running") {
document.body.removeEventListener("touchend", resume, false);
document.body.removeEventListener("mouseup", resume, false);
}
}, 0);
}
document.body.addEventListener("touchend", resume, false);
document.body.addEventListener("mouseup", resume, false);
});
/**
* Mobile Safari will start Audio contexts in a "suspended" state.
* A user interaction (touch event) is needed in order to resume the AudioContext.
*/
const iDevices = /\biPhone.*Mobile|\biPod|\biPad|AppleCoreMedia/;
if (iDevices.test(navigator.userAgent)) {
document.addEventListener("DOMContentLoaded", () => {
const ctx = THREE.AudioContext.getContext();
function resume() {
ctx.resume();
setTimeout(function() {
if (ctx.state === "running") {
document.body.removeEventListener("touchend", resume, false);
}
}, 0);
}
document.body.addEventListener("touchend", resume, false);
});
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment