SoundPool 错误:没有更多可用的曲目名称

发布于 2024-12-19 17:42:44 字数 681 浏览 0 评论 0原文

我在 soundpool 类上遇到了麻烦。事情是这样的:

在我的游戏应用程序(顺便说一句,音乐应用程序)中,我需要同时再现至少 32 个短声音,所以我这样声明我的声音池:

private SoundPool sp;
sp = new SoundPool(128, AudioManager.STREAM_MUSIC, 0);

之后我加载所需的所有 MP3 声音,大约 80 个 55KB 的声音每个。我可以轻松加载所有声音,但速度很慢!好吧,这不是问题。真正的麻烦是,当我同时播放大约 20 个声音时,我的日志中出现错误:

ERROR/AudioFlinger(59): no more track names available
ERROR/AudioTrack(26349): AudioFlinger could not create track, status: -12
ERROR/SoundPool(26349): Error creating AudioTrack

之后我尝试播放的每个声音都会抛出相同的错误,并且无法播放任何声音。甚至没有另一个活动/声音池的声音。我不知道发生了什么或如何解决它!我应该更改声音文件的格式吗?播放声音后我应该释放内存或其他东西吗?

(我正在三星 Galaxy S I9000、2.3.3 OS 系统上进行测试。应用程序是 2.1)

I'm having troubles with the soundpool class. Here it goes:

In my game app (music app btw) I need to reproduce at least 32 short sounds at the same time, so I declare my soundpool like that:

private SoundPool sp;
sp = new SoundPool(128, AudioManager.STREAM_MUSIC, 0);

After that I load all the MP3 sounds needed, about 80 sound of 55KB each. I have no troubles loading all the sounds, but its slow! Well it's no the problem. The real trouble is when I play about 20 sounds at the same time, there's an error in my log:

ERROR/AudioFlinger(59): no more track names available
ERROR/AudioTrack(26349): AudioFlinger could not create track, status: -12
ERROR/SoundPool(26349): Error creating AudioTrack

After that every sound that i try to play throws the same error, and no sound can be played. Not even sounds of another Activity / soundpool. I have no clue of what's going or how to fix it! Should I change the format of the sound files? Should I free memory or something after playing a sound?

(I'm testing on a Samsung Galaxy S I9000, 2.3.3 OS system. The app is 2.1)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

智商已欠费 2024-12-26 17:42:44

请参阅此内容(在 Android 群组中)

了解音频,每个设备有 32 个活动 AudioTrack 对象的硬限制(不是每个应用程序:
您需要与系统的其他部分共享这 32 个),

see this (in android group)

For audio, there's a hard limit of 32 active AudioTrack objects per device (not per app:
you need to share those 32 with rest of the system),

墨小沫ゞ 2024-12-26 17:42:44

这里有一些想法。一:SoundPool 构造函数的第一个参数不是要加载到其中的声音数量,而是要播放的并发流的最大数量。其次,SoundPool 的声音内存有限,大约为 1MB。因此,如果您一次可以加载的曲目数量达到了一些未记录的限制,我一点也不会感到惊讶。请注意,80 个声音乘以每个声音 55k 绝对超过 1MB。该限制是在将 mp3 解压缩为 SoundPool 内的音频数据之后的限制。

A couple of thoughts here. One: the first parameter to the SoundPool constructor is not the number of sounds you want to load into it, it's the maximum number of simultaneous streams that you'll be playing. Second, SoundPool has limited memory for sounds, about 1MB. So I wouldn't be at all surprised if you hit some undocumented limit to the number of tracks you can load in at one time. Notice that 80 sounds times 55k per sound is definitely over 1MB. And that limit is for after the mp3s have been uncompressed into audio data inside SoundPool.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文