AVAudioPlayer has a method playAtTime:
which takes care of t1, however there’s no easy way to stop playing at a specific time (t2).
As of iOS8 AVFoundation has new api’s such as AVAudioEngine and AVAudioPlayerNode. You may find implementing AVAudioPlayerNode instead is more suited for your requirements as it has a method named
- scheduleSegment:startingFrame:frameCount:atTime:completionHandler:
which is for playing a segment of an audio file.
2
solved How to play an mp3 file in Xcode from time t1 to t2 with AVAudioPlayer