diff --git a/Tone/core/context/ToneAudioBuffer.test.ts b/Tone/core/context/ToneAudioBuffer.test.ts index 3258ab32..e0b97636 100644 --- a/Tone/core/context/ToneAudioBuffer.test.ts +++ b/Tone/core/context/ToneAudioBuffer.test.ts @@ -117,6 +117,39 @@ describe("ToneAudioBuffer", () => { }); }); + context("baseUrl", () => { + afterEach(() => { + // reset baseUrl + ToneAudioBuffer.baseUrl = ""; + }); + + it("can resolve a url without a baseUrl", async () => { + const buffer = new ToneAudioBuffer("./test/audio/sine.wav"); + expect(buffer.loaded).to.be.false; + await ToneAudioBuffer.loaded(); + expect(buffer.loaded).to.be.true; + expect(buffer.duration).to.be.closeTo(3, 0.01); + }); + + it("can resolve a url with a baseUrl", async () => { + ToneAudioBuffer.baseUrl = "./test/audio"; + const buffer = new ToneAudioBuffer("sine.wav"); + expect(buffer.loaded).to.be.false; + await ToneAudioBuffer.loaded(); + expect(buffer.loaded).to.be.true; + expect(buffer.duration).to.be.closeTo(3, 0.01); + }); + + it("can resolve a url with a baseUrl that has a trailing slash", async () => { + ToneAudioBuffer.baseUrl = "./test/audio/"; + const buffer = new ToneAudioBuffer("sine.wav"); + expect(buffer.loaded).to.be.false; + await ToneAudioBuffer.loaded(); + expect(buffer.loaded).to.be.true; + expect(buffer.duration).to.be.closeTo(3, 0.01); + }); + }); + context("loading", () => { it("invokes the error callback if there is a problem with the file", (done) => { const buffer = new ToneAudioBuffer( @@ -141,20 +174,6 @@ describe("ToneAudioBuffer", () => { expect(hadError).to.equal(true); }); - it("can load a file with fallback extensions", async () => { - const buffer = await ToneAudioBuffer.load( - "./test/audio/sine.[nope|nada|wav]" - ); - expect(buffer).to.exist; - }); - - it("takes the first supported format when multiple extensions are provided", async () => { - const buffer = await ToneAudioBuffer.load( - "./test/audio/sine.[wav|nope]" - ); - expect(buffer).to.exist; - }); - it("instance .load method returns Promise", (done) => { const promise = new ToneAudioBuffer().load(testFile); expect(promise).to.have.property("then"); diff --git a/Tone/core/context/ToneAudioBuffer.ts b/Tone/core/context/ToneAudioBuffer.ts index be983737..d9584f8f 100644 --- a/Tone/core/context/ToneAudioBuffer.ts +++ b/Tone/core/context/ToneAudioBuffer.ts @@ -372,20 +372,6 @@ export class ToneAudioBuffer extends Tone { * Loads a url using fetch and returns the AudioBuffer. */ static async load(url: string): Promise { - // test if the url contains multiple extensions - const matches = url.match(/\[([^\]\[]+\|.+)\]$/); - if (matches) { - const extensions = matches[1].split("|"); - let extension = extensions[0]; - for (const ext of extensions) { - if (ToneAudioBuffer.supportsType(ext)) { - extension = ext; - break; - } - } - url = url.replace(matches[0], extension); - } - // make sure there is a slash between the baseUrl and the url const baseUrl = ToneAudioBuffer.baseUrl === "" || @@ -393,15 +379,7 @@ export class ToneAudioBuffer extends Tone { ? ToneAudioBuffer.baseUrl : ToneAudioBuffer.baseUrl + "/"; - // encode special characters in file path - const location = document.createElement("a"); - location.href = baseUrl + url; - location.pathname = (location.pathname + location.hash) - .split("/") - .map(encodeURIComponent) - .join("/"); - - const response = await fetch(location.href); + const response = await fetch(baseUrl + url); if (!response.ok) { throw new Error(`could not load url: ${url}`); }