1π
β
I guess the error happens because the Player
is not yet done with the download of the audio.
The constructor doesnβt return a promise. If you want to wait for the Player
to be ready you need to pass an onload
function. It can be used to wait for the Player
to be ready by wrapping it in a promise.
this.player = await new Promise((resolve, reject) => {
const player = new Tone.Player({
loop: true,
onerror: (err) => reject(err),
onload: () => resolve(player),
url: '/sounds/rain.wav'
});
});
this.player.toDestination();
π€chrisguttandin
Source:stackexchange.com