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

查看:22
本文介绍了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?

谢谢.

弗洛里安

推荐答案

解决方案如下:

将音频会话类别设置为 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天全站免登陆