Android SoundPool 有多糟糕?使用什么替代方案? [英] How bad is Android SoundPool? What alternative to use?
问题描述
我将 Android 的 SoundPool
作为在我的通用游戏开发库中实现音效的机制.看起来很理想.
I was looking at Android's SoundPool
as a mechanism to implement sound effects in my generic game development library. It seemed ideal.
但一点点研究表明,所有 种类 of 错误.SoundPool
中的错误是否仍然相关?
But a little bit of research indicates that there all kinds of bugs in SoundPool
. Are the bugs in SoundPool
still relevant?
因为我正在开发一个库,SoundPool
中的任何错误都会成为我的库中的错误,我想让我的用户远离它.
Because I'm developing a library, any bugs in SoundPool
become bugs in my library, and I want to insulate my users from that.
所以我的问题基本上是:我应该为音频使用什么 API?
So my question is basically: what API should I use for audio?
使用 AudioTrack
并编写我自己的混音器并非不可能.但显然最好避免这样做.是否有任何 API 可以为我提供解码?
Using AudioTrack
and writing my own mixer is not out of the question. But obviously it would be preferable to avoid doing that. And is there any API to provide decoding for me?
我需要能够同时播放合理数量的音效(比如说至少 16 个),并且有更多的开放性.声音需要以低延迟开始播放.需要支持 WAV
文件(MP3/Ogg 不重要).音效需要支持无缝循环和动态的、单独的音量调节.需要适当支持 Android 应用生命周期.
I need to be able to play a reasonable number of simultaneous sound effects (at least 16, let's say), and have even more open. Sounds need to start playing with low latency. WAV
files need to be supported (MP3/Ogg is unimportant). Sound effects need to support seamless looping and dynamic, individual volume adjustment. The Android app lifecycle needs to be properly supported.
我听说 SoundPool
在某处有 1MB 的限制,这对于每个单独的音效可能是可以接受的,但不是所有缓冲区/声音都可以接受.有人能告诉我具体的限制是什么吗?
I have heard there is a 1MB limit somewhere for SoundPool
, this is probably acceptable for each individual sound effect but not for all buffers/sounds. Can someone tell me exactly what the limit is on?
最后,我还需要能够以压缩格式播放背景音乐,并且 CPU 负载较低.我认为 MediaPlayer
是这个的理想选择.是否可以与其他 API 并行使用?
Finally, I need to be able to play background music as well, in compressed formats, with low CPU load. I assume MediaPlayer
is ideal for this. Can it be used in parallel with another API?
我知道有些人一直在使用 MediaPlayer
来填充 SoundPool
.但它是否支持我需要的功能?
I know a few people have been using MediaPlayer
to fill in for SoundPool
. But does it support the features that I need?
还有我遗漏的其他音频 API 吗?
Are there any other audio APIs I've missed?
推荐答案
只是为了添加一些关于此问题的最新反馈.我已经在一个应用程序中使用 SoundPool 一段时间了,该应用程序具有相当大的按键声音用户群.我们的用例:
Just to add some more recent feedback on this issue. I've been using SoundPool for some time in an app with a fairly large user base for key press sounds. Our use case:
- 必须立即播放
- 最多可同时播放 3 个以上的声音
- 我们在整个范围内使用
setRate
[0.5f-2.0f]
我现在遇到了两个主要的设备特定问题,并决定减少损失并退出 SoundPool
I've now experienced two major device specific issue and have decided to cut my losses and switch away from SoundPool
- 大量 4.4 LG 设备(主要是 LG G2/G3 系列)在实施 SoundPool 时发生了本机崩溃.这已在更新中修复(最终),但我们仍有很多用户使用未升级的设备
- 索尼 Xperia 设备目前在 SoundPool 方面存在各种问题,例如 其他人举报.就我而言,我发现如果您使用
setRate
和rate >1.0f
SoundPool 开始抛出异常,直到您的应用退出(并在此过程中消耗大量电池).
- A large number of 4.4 LG devices (mostly the LG G2/G3 line) were having a native crash with their implementation of SoundPool. This was fixed in an update (eventually) but we still have a lot of users with un-upgraded devices
- Sony Xperia devices currently have all sorts of issue with SoundPool as reported by others. In my case, I've discovered that if you use
setRate
withrate > 1.0f
the SoundPool with start throwing exceptions until your app quits (and burn through a bunch of battery in the process).
TL;博士;我不再认为调试 SoundPool 的危险/麻烦值得
TL;DR; I no longer think it's worth the danger/hassle of debugging SoundPool
这篇关于Android SoundPool 有多糟糕?使用什么替代方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!