1

I have an AVAudioPlayerNode (playerNode) and two AVAudioPCMBuffer (buffer1, buffer2) setup.

I also have a AVAudioTime (futureTime) setup for 10 seconds.

var options: AVAudioPlayerNodeBufferOptions = []
options.insert(.interruptsAtLoop)
options.insert(.loops)

playerNode.scheduleBuffer(buffer1!,
    at: futureTime,
    options: options,
    completionHandler:nil)

The above plays buffer1 after waiting 10 seconds and keeps playing it in a loop.

Calling the following code:

playerNode.scheduleBuffer(buffer2!,
    at: futureTime,
    options: options,
    completionHandler:nil)

Is causing buffer1 to stop playing and buffer2 to start immediately instead of waiting at least 10 seconds and then interrupting at the next loop of buffer1.

Any ideas what I'm doing wrong that is causing this immediate interruption instead of interrupting at the loop as instructed?

Andrew Sage
  • 111
  • 2
  • 6

1 Answers1

0

I haven't used the AVAudioTime class directly, but looking at the API it appears to represent an exact moment in time, not a relative one. If that's true, then by using the same "futureTime" twice, you are scheduling buffer2 to start at the same time as buffer 1. Maybe you can calculate a futureTime2 10 seconds after the first one.

Brian A
  • 361
  • 4
  • 5