I am wondering what the best solution to looping audio for a defined duration on iOS is. I am currently playing around with
AVAudioPlayer(where I can define a repeat count but can't define an end-time)AVPlayer(where I can define aforwardPlaybackEndTimebot not a loop count)AVPlayerLooper(that I don't yet fully understand)
So what I need is to define a duration for which a certain sound-file is repeated. F.e. I have a 8 second mp3 and want to play it for f.e one minute.
What would also be suuuuper great, is if I could cross-fade when it starts over again.
You were on the right track with AVPlayerLooper.
This is how you setup
AVPlayerLooperTo stop the loop after a set amount of time you can use addBoundaryTimeObserver(forTimes:queue:using:) For example:
For fading in/out you have to set the
audioMixproperty to yourAVPlayerIteminstance before using it.Complete function: