AVAudioEngine stuttering when pausing and playing

Hi,


We're trying to debug and correct a most bizarre issue with AVAudioEngine.


We are using AVAudioEngine to play an MPEG4 wrapped AAC file and we're hearing stuttering when we play() after we have paused() the engine.


Here's our implementation for both pause() and play():


func play() throws {

// add any taps we want


if !engine.isRunning {

try engine.start()

}

audioPlayerNode.play()

}

/

func pause() {

// remove any taps we have


audioPlayerNode.pause()

engine.pause()

}


where engine is an AVAudioEngine instance, and audioPlayerNode is an AVAudioPlayerNode instance.


Has anyone ever encountered this sort of behavior? How did you resolve this?

Accepted Reply

Just after I posted this, I realized I should actually call reset() on the engine when I pause or restart the engine to flush all of the buffers within the nodes.

Replies

I've noticed that if I don't pause() the engine; the stuttering goes away. So, it seems to me like I'm being too aggresive in pausing the engine(), resulting in some audio remaining within the internal buffers.

Just after I posted this, I realized I should actually call reset() on the engine when I pause or restart the engine to flush all of the buffers within the nodes.