Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

webaudio, audiocontext jump to position

In my code I set AudioContext.currentTime to jump to a different position in the playing track. This does not work. It's old code, so I am not sure if the webaudio specifications have changed or I just created wrong code. I've been searching for a solution to how this should work for ages now. The only solutions I have seen, seem to involve stopping the old sound and creating a new buffersource.

is there no way to specify the position within the playing track?

edit: I am aware that AudioContext.currentTime is now specified as readonly

like image 803
marcgfx Avatar asked May 09 '15 00:05

marcgfx


1 Answers

I do it like this:

  function playAudio(buffer, offsetInSeconds, duration) {
    console.log('start playing audio');
    var audioTrack = context.createBufferSource();
    audioTrack.connect(context.destination);
    audioTrack.buffer = buffer;     
    audioTrack.start(context.currentTime, offsetInSeconds,  duration);        
  }

And yes, you have to create new bufferSource everytime.

like image 195
user3357257 Avatar answered Oct 03 '22 04:10

user3357257