fix: load base64 encoded sounds when baseUrl is not empty

Fixes #898
This commit is contained in:
Ilya Apasov 2021-05-26 12:59:44 +02:00 committed by GitHub
parent c19723905e
commit a77181175a
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, onerror: (e: Error) => void = noOp,
): this { ): this {
if (isString(url)) { 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)); this._buffers.set(name.toString(), new ToneAudioBuffer(this.baseUrl + url, callback, onerror));
} else { } else {
this._buffers.set(name.toString(), new ToneAudioBuffer(url, callback, onerror)); this._buffers.set(name.toString(), new ToneAudioBuffer(url, callback, onerror));