Tone.js
Tone.js copied to clipboard
Unable to have a callback when the player completes playing the song
Hi,
I would like to setup a callback when the player completes playing the given url. I have already tried the events in tone.transport: pause or stop, they are not invoked.
const setEvents = () => {
Tone.Transport.on("start", (...args) => {
console.log("startd: ", args);
});
Tone.Transport.on("stop", (...args) => {
console.log("stopped: ", args); // NOT INVOKED WHEN THE SONG COMPLETES
});
};
const playAudio = async (
url: string,
bpm: number = 120
): Promise<Tone.Player | null> => {
await initializeTone();
Tone.Transport.bpm.value = bpm;
// Load and play the new audio
const player = new Tone.Player(url).sync().toDestination();
await Tone.loaded();
Tone.Transport.start();
player.start();
};
Thanks