[Vuejs]-Can't get Tone.js player to work and play a single wav file

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();

Leave a comment