How do I stop audiobuffers made with scripting?

0 favourites
  • 4 posts
  • I am using the Sound Synthesis scripting example. In the example, each buffer plays the sound for a fixed amount of time. I want the option to stop it early.

    Is there a way to stop an audiobuffer that is already in progress? I am certain that my wording isn't right, but I hope the meaning is clear. I tried reading the audiocontext and audiobuffer mdn documentation but couldn't figure out how to use .close() in context or whether that is even the right method.

    Tagged:

  • This is just a general question about the Web Audio API. The start() method of a source node will begin playback, and the stop() method stops it.

  • Thank you for responding.

    I can use .stop() within the same function that starts the audio, but I cannot figure out how to use it in a separate function to accomplish something like stopping the sound with a button. I am getting an error like,

    Failed to execute 'stop' on 'AudioScheduledSourceNode': cannot call stop without calling start first.

    I apologize if helping me is outside of the scope of this forum.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • It's hard to tell exactly what you are doing without seeing the code, having said that I imagine that what is happening is that in the function you are attempting to stop the audio source node you might be just creating a new one and that is why it tells you that you can not call stop() without calling start() first.

    If that is the problem, what you need to do is keep the reference to the audio source node, so you can access the same one in the function you want to stop it.

    Of course, if you can share a snippet of what you are trying to do, it will be much easier to help you.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)