From 512f123cfa006ffa8e648656f15e0d5aed375e27 Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Sun, 11 Feb 2018 13:55:55 -0800 Subject: [PATCH] Fix ios --- js/media/index.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/js/media/index.js b/js/media/index.js index acc3129a..ea650da7 100644 --- a/js/media/index.js +++ b/js/media/index.js @@ -5,6 +5,21 @@ import ElementSource from "./elementSource"; export default class Media { constructor() { this._context = new (window.AudioContext || window.webkitAudioContext)(); + // Fix for iOS: https://gist.github.com/laziel/7aefabe99ee57b16081c + // Via: https://stackoverflow.com/a/43395068/1263117 + if (this._context.state === "suspended") { + const resume = () => { + this._context.resume(); + + setTimeout(() => { + if (this._context.state === "running") { + document.body.removeEventListener("touchend", resume, false); + } + }, 0); + }; + + document.body.addEventListener("touchend", resume, false); + } this._callbacks = { waiting: function() {}, stopWaiting: function() {},