I had problems trying to create seamless loops. I tried using the numberOfLoops
property, with no success. I tried switching to uncompressed audio files, with no success. I even tried switching to an AVAudioQueuePlayer
, queued with multiple instances of the same asset, with no success. In the end I solved the problem by creating two instances of AVAudioPlayer
(player1 & player2) and switching between them. I began playback of player1 and used player2's prepareToPlay
method, and the play(atTime time:)
method setting the TimeInterval to player1.deviceCurrentTime - player1.currentTime + player1.duration
.
I then used the delegate method audioPlayerDidFinishPlaying
to prepare player1 to restart playback after player2 was done. To be honest, I don't know why this approach worked and simply setting numberOfLoops
to -1 did not. But it may work for you also