javascriptweb-audio-api

JS/Web Audio: How do I jump to loopStart immediately, while playing?


I'm working with the Web Audio API in javascript. Part of my current project involves a looper, I need to change the start and end points of the looper dynamically. Which is working.

But I need the playback position of the audio file to move to the start point when I set it. I've been googling and reading the spec for days, but I can't seem to find an answer.

I know you can set it with the start() function, but I need to change it while it is already playing. Thanks!


Solution

  • If I understand what you're trying to do, I think the only way to do this is to create a new AudioBufferSource using the same buffer. Adjust this new AudioBufferSource with the same loop points as the original and then call start() with the correct start time and offset.