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

366
Visualizações
Having trouble playing audio on "touchstart" and then pausing audio on "touchend". I am using Howler.JS library to do so

Having trouble playing audio on "touchstart" and then pausing audio on "touchend". I am using Howler.JS library to do so. Please let me know if you can help. Goal is to just play some audio as the user touches anywhere on the screen. Then pause the audio when the user lifts their finger. At the moment, I have the audio playing ontouch. However, the pause listener is not responding. Any ideas?

Howler JS link: https://github.com/goldfire/howler.js

<script>
    document.addEventListener("touchstart", function(event) {
        var sound = new Howl({
            src: ['./audio/spray.mp3'],
        });
        sound.play();
    });
    document.addEventListener("touchend", function(event) {
        var sound = new Howl({
            src: ['./audio/spray.mp3'],
        });
        sound.pause();
        sound.currentTime = 0;
    });
</script>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It's been a long time without using Howler but I think the issue is that the Howler sound instances are different. When you do:

var sound = new Howl({
 src: ['./audio/spray.mp3'],
});

You create a different instance with a different ID. If I remember correctly you can pause the sound with the ID or referencing the same instance.

So, you have to keep a reference to the sound instance being played.

about 4 years ago · Juan Pablo Isaza Relatório
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