AVAudioPlayer-帧率下降 [英] AVAudioPlayer - Drop in Framerate

查看:78
本文介绍了AVAudioPlayer-帧率下降的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个快速的问题:我正在将mp3文件加载到NSData对象中,然后在游戏中使用AVAudioPlayer播放它.每隔一秒钟左右,帧速率就会下降,并且您会在屏幕上看到结结.这不是主要的放慢速度,但明显可察觉并破坏了游戏玩法.不使用AVAudioPlayer播放音乐曲目完全不会减慢速度.

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?

谢谢.

弗洛里安

推荐答案

供以后参考,以下是解决方案:

For future reference, here is the solution:

将音频会话类别设置为kAudioSessionCategory_AmbientSound(以允许iPod音乐同时播放)会以某种方式禁用MP3硬件加速.将音频类别设置为kAudioSessionCategory_SoloAmbientSound可以解决此问题,但不允许iPod播放.现在,我根据启用还是禁用背景音乐来设置音频会话类别,以允许同时播放iPod.

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.

这篇关于AVAudioPlayer-帧率下降的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆