SoundPool error: no more track names available

耗尽温柔 提交于 2019-12-18 12:56:11

问题


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)


回答1:


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),




回答2:


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.



来源:https://stackoverflow.com/questions/8388053/soundpool-error-no-more-track-names-available

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!