AVAudioPlayer - Drop in Framerate

﹥>﹥吖頭↗ 提交于 2019-12-01 05:38:42

问题


I have a quick question: I am loading a mp3 file into a NSData object and then I play it using the AVAudioPlayer in my game. Every second or so, the frame rate drops and you can see a stuttering on the screen. It is not a major slowdown, but clearly noticeable and disrupting to the gameplay. Not playing the music track with the AVAudioPlayer shows no slow down at all.

How can I prevent this from happening?

Thank you.

Florian


回答1:


For future reference, here is the solution:

Setting the audio session category to kAudioSessionCategory_AmbientSound (to allow for iPod music to play simultaneously) somehow disables MP3 hardware acceleration. Setting the audio category to kAudioSessionCategory_SoloAmbientSound fixes this, but doesn't allow for iPod playback. I do now set the audio session category depending on whether background music is enabled or disabled to allow for simultaneous iPod playback.




回答2:


The mp3 is an encoded/compressed audio format. You can try either to reduce the sampling rate (for istance, instead of 128 kb/s try 64 kb/s) or switch to a non encoded format such as linear pcm. The cons are: lower audio quality in the former case, higher file size in the latter. But this can help improve the overall performances of your app.



来源:https://stackoverflow.com/questions/1009385/avaudioplayer-drop-in-framerate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!