'Pop noise' sounds when audio paused with Javascript

后端 未结 1 877
囚心锁ツ
囚心锁ツ 2021-01-16 08:30

I have an audio tag in my html, and which I have .wav inside it. With Javascript, I select audio tag and play the wav., which I trigger using a keyboard key. What I am t

相关标签:
1条回答
  • 2021-01-16 09:13

    Update:

    I think I need to use fade out to work around this issue. Is there a way to fade out audio instantly?

    You can use .animate() to animate volume property from current value to 0

    var audio = $("audio");
    $("button").click(function() {
      if (audio[0].volume > 0) {
        audio.animate({volume:0});
        // call `.pause()` here
      }
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <audio controls  src="https://upload.wikimedia.org/wikipedia/commons/6/6e/Micronesia_National_Anthem.ogg"></audio>
    <button>fade out audio</button>

    0 讨论(0)
提交回复
热议问题