I want to play a specified duration within a sound file on IOS. I found a method in AVAudioPlayer that seeks to the begining of the playing (playAtTime:) but i cannot find a direct way to specify an end time before the end of the sound file.
Is there is a way to achieve this?
If you don’t need much precision and you want to stick with
AVAudioPlayer, this is one option:Bear in mind that
stopTimerwill fire on the thread’s run loop, so there will be some variability in how long the audio plays, depending on what else the app is doing at the time. If you need a higher level of precision, consider usingAVPlayerinstead ofAVAudioPlayer.AVPlayerplaysAVPlayerItemobjects, which let you specify aforwardPlaybackEndTime.