开发者

Can AVPlayer pre-buffer audio similar to AVAudioPlayer's preparetoplay?

开发者 https://www.devze.com 2023-02-17 15:46 出处:网络
Is there a way to make AVPlayer load audio into a buffer like AVAudioPlayer does when called to prepare开发者_C百科toplay?I\'m trying to eliminate the lag time between when a user presses a play butto

Is there a way to make AVPlayer load audio into a buffer like AVAudioPlayer does when called to prepare开发者_C百科toplay? 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消