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

Unable to have a callback when the player completes playing the song

Open logesh2496 opened this issue 1 year ago • 0 comments

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

logesh2496 avatar Oct 19 '23 06:10 logesh2496