Merge pull request #899 from apasov/patch-3

fix: load base64 encoded sounds when baseUrl is not empty
This commit is contained in:
Yotam Mann 2021-05-30 12:11:56 -04:00 committed by GitHub
commit a2a13dfe51
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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));