Is there a way to make AVPlayer load audio into a buffer like AVAudioPlayer does when called to preparetoplay? I'm trying to eliminate the lag time between when a user presses a play button and the audio begins playing. AVAudioPlayer seems more instantaneous but I need to play files from the iPod library.
1 Answers
If you are using AVPlayer to play a song from a URL then when you call 'play' on AVPlayer it starts to load the song and then plays when its ready. I would assume it's the same functionality if the file is local. If it's coming from your iPod then the lag time should be very small already.
One thing you should try is calling play then pause and AVPlayer will continue to load the song so when you call play again (assuming it's not immediate) then the song should start without any problems. I can confirm this works when playing a song from a URL. Try it out for your scenario.
- (void) getPlayerReady {
// write some code here to setup the player
[player play];
[player pause];
}
- (IBAction) btnPlayTouched:(id)sender {
[player play];
}
EDIT: I guess I should also mention that AVQueuePlayer will do this for you. If you give AVQueuePlayer multiple songs it will automatically pre-buffer the next song while the first song is playing. I don't know if this is something that you can use in your situation or not.