Slow start for AVAudioPlayer the first time a sound is played

后端 未结 9 1360
孤城傲影
孤城傲影 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:42

    I wrote a simple wrapper for AVAudioPlayer that provides a prepareToPlay method that actually works:

    https://github.com/nicklockwood/SoundManager

    It basically just scans your app for sound files, picks one and plays it at zero volume. That initialises the audio hardware and allows the next sound to play instantly.

提交回复
热议问题