Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

212
Visualizações
Delay between .play() and actually hearing the sound?

So I'm making a piano website where the user can draw in notes and play them. A playhead goes across the screen and whatever notes are under it get played.

I have a state called played for each note which tracks if the note is being played or not.


 const note = useRef(new Audio(props.filePath));
 note.current.preload = "auto";
 useEffect(() => {
        if (played) {
            note.current.play();
        } else {
            note.current.pause();
        }
    }, [played]);

I have a useRef to access the sound to prevent it from reloading when the component renders.

I also have a state called progress which constantly updates as the playhead moves. But I don't think this should be an issue since the sound is preloaded.

My problem is that even though the .play() command executes, the sound still takes a few seconds to be heard.

For example, right after the .play() call, I logged the note.paused value, which came out false. So this means that the note is being played, but I just can't hear it.

For some reason, if a note is currently playing, and the playhead loops back and plays the same note again, the sound is heard instantly. But if I pause the playhead and wait for the audio to end, and then play again, the delay is back.

So how do I make it so that the note is heard as soon as the playhead reaches the note everytime?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda