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?
Thank you.
Florian
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了供将来参考,这里是解决方案:
将音频会话类别设置为 kAudioSessionCategory_AmbientSound(以允许 iPod 音乐同时播放)会以某种方式禁用 MP3 硬件加速。 将音频类别设置为 kAudioSessionCategory_SoloAmbientSound 可以修复此问题,但不允许 iPod 播放。 我现在根据是否启用或禁用背景音乐来设置音频会话类别,以允许同时 iPod 播放。
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.
mp3 是一种编码/压缩的音频格式。 您可以尝试降低采样率(例如,尝试 64 kb/s,而不是 128 kb/s)或切换到非编码格式,例如线性 pcm。 缺点是:前者的音频质量较低,后者的文件大小较大。 但这可以帮助提高应用程序的整体性能。
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.