Slow start for AVAudioPlayer the first time a sound is played

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

    Other workaround is to create a short & silent audio and play it on the first time player is initiated.

    1. Set the microphone level to 0 on System Preferences.
    2. Open QuickTime.
    3. Create new Audio Recording (File > New Audio Recording).
    4. Record for 1 or 2 second.
    5. Save / Export the audio file. (it will have .m4a extension and about 2 kb on size).
    6. Add the file to your project and play it.

    If you dont want to create a new sound file yourself, you may download a short & silent audio file here : https://www.dropbox.com/s/3u45x9v72ic70tk/silent.m4a?dl=0

提交回复
热议问题