Ability to pass credentials and other fetch parameters when fetching audio buffers
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.
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.
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 isRequestInitin 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.
🙏🏻