From a77181175a0cd7088f0f47114ad934a66969631c Mon Sep 17 00:00:00 2001 From: Ilya Apasov Date: Wed, 26 May 2021 12:59:44 +0200 Subject: [PATCH] fix: load base64 encoded sounds when baseUrl is not empty Fixes #898 --- Tone/core/context/ToneAudioBuffers.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Tone/core/context/ToneAudioBuffers.ts b/Tone/core/context/ToneAudioBuffers.ts index 44f86465..dd44727e 100644 --- a/Tone/core/context/ToneAudioBuffers.ts +++ b/Tone/core/context/ToneAudioBuffers.ts @@ -147,6 +147,10 @@ export class ToneAudioBuffers extends Tone { onerror: (e: Error) => void = noOp, ): this { if (isString(url)) { + // don't include the baseUrl if the url is a base64 encoded sound + if (this.baseUrl && url.trim().substring(0, 11).toLowerCase() === "data:audio/") { + this.baseUrl = ""; + } this._buffers.set(name.toString(), new ToneAudioBuffer(this.baseUrl + url, callback, onerror)); } else { this._buffers.set(name.toString(), new ToneAudioBuffer(url, callback, onerror));