From 29d56dc47caec90b6d998bfed5f9bc17fbb552f0 Mon Sep 17 00:00:00 2001 From: shaders Date: Mon, 6 Sep 2021 00:09:05 +0700 Subject: [PATCH] Update pcm-player.js ios and safari support --- pcm-player.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pcm-player.js b/pcm-player.js index eb5a73f..9da3f81 100644 --- a/pcm-player.js +++ b/pcm-player.js @@ -42,6 +42,11 @@ PCMPlayer.prototype.getTypedArray = function () { PCMPlayer.prototype.createContext = function() { this.audioCtx = new (window.AudioContext || window.webkitAudioContext)(); + + // context needs to be resumed on iOS and Safari (or it will stay in "suspended" state) + this.audioCtx.resume(); + this.audioCtx.onstatechange = () => console.log(this.audioCtx.state); // if you want to see "Running" state in console and be happy about it + this.gainNode = this.audioCtx.createGain(); this.gainNode.gain.value = 1; this.gainNode.connect(this.audioCtx.destination); @@ -123,4 +128,4 @@ PCMPlayer.prototype.flush = function() { bufferSource.start(this.startTime); this.startTime += audioBuffer.duration; this.samples = new Float32Array(); -}; \ No newline at end of file +};