Skip to content

Audio overlapping after audio is stop/pause and then plays #1557

Discussion options

You must be logged in to vote

We solved the issue by calling clearTimeout when a click event occurs.

First, we reformated arpeggios function as below (Note: playArp is a global variable (default is []) that holds setTimeout functions)

   function arpeggios(
    chordMidiNumbers: Array<number>,
    i: number,
    length: number
  ) {
    const temp = setTimeout(() => {
      sound.play(chordMidiNumbers[i].toString());
      i++;
      if (i < length) arpeggios(chordMidiNumbers, i, length);
    }, 1500);
    playArp.push(temp);
  }

Then, we call clearArp function when a click event happens (stop all playing sounds then play the selected chord):

  function clearArp() {
    for (const item of playArp) {
      clearTimeou…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by rolandlee0308
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant