Slow start for AVAudioPlayer the first time a sound is played

后端 未结 9 1357
孤城傲影
孤城傲影 2020-12-02 09:23

I\'m trying to eliminate startup lag when playing a (very short -- less than 2 seconds) audio file via AVAudioPlayer on the iPhone.

First, the code:

         


        
9条回答
  •  长情又很酷
    2020-12-02 09:48

    The delay seems to be related to instantiating AVAudioPlayer for the first time. If I load any audio, run [audioPlayer prepareToPlay] and then immediately release it, the load times for all of my other audio is very close to imperceptible. So now I'm doing that in applicationDidFinishLaunching and everything else runs well.

    I can't find anything about this in the docs, but it certainly seems to be the case.

提交回复
热议问题