Tone.js icon indicating copy to clipboard operation
Tone.js copied to clipboard

Ability to pass credentials and other fetch parameters when fetching audio buffers

Open zya opened this issue 4 years ago • 4 comments

The feature you'd like Update ToneAudioBuffer.load and in places that is used (e.g. Player.load) to take an optional extra parameter reflecting fetch options. This is to be able to pass things such as headers and credentials when loading audio files.

const buffer = await ToneAudioBuffer.load(url, {
  credentials: 'include',
  headers: {
     'custom': 'header'
  },
  // ...other options supported by fetch
});

// player
const player = new Player(url, { .... fetch options similar to above })

Any alternatives you've considered Currently the alternative would be to to do a fetch outside of Tone, convert to buffer and pass to Player. Which is fine, but maybe this is something that the Tone loaders could handle.

Additional context Just wanted to discuss with the community to see if this is something that aligns with Tone general direction. If so, I can create a PR.

zya avatar Sep 14 '21 11:09 zya

thanks @zya i'm into this feature!

a PR would be great and should be relatively simple. You're imagining that the second argument would be passed in entirely to fetch? Looks like the second arg type is RequestInit in lib.dom.d.ts.

tambien avatar Sep 16 '21 17:09 tambien

thanks @zya i'm into this feature!

a PR would be great and should be relatively simple. You're imagining that the second argument would be passed in entirely to fetch? Looks like the second arg type is RequestInit in lib.dom.d.ts.

Yeah, that's what I was thinking. A second optional argument of type RequestInit for ToneAudioBuffer.load and for Player. I'll do a PR soon.

zya avatar Sep 16 '21 19:09 zya

🙏🏻

tambien avatar Sep 17 '21 13:09 tambien