AudioFlinger无法创建轨道。状态:-12轨道、状态、AudioFlinger

2023-09-14 23:02:15 作者:╮稍纵即逝

我编程为Android 2.2,我试图用 的Soundpool 类,同时但在什么感觉就像随机倍音速玩几个声音将停止现身扬声器。

I am programming for android 2.2 and am trying to using the SoundPool class to play several sounds simultaneously but at what feel like random times sound will stop coming out of the speakers.

有关,将被打了,这是印在logcat中每个声音:

for each sound that would have been played this is printed in the logcat:

AudioFlinger could not create track. status: -12 
Error creating AudioTrack
Audio track delete

没有异常被抛出,程序可以继续,而不只是缺乏成交量的任何变更执行。我有一个很艰难的时期追查什么条件下会导致错误或重新创建它发生之后。我找不到任何地方文档中的错误和上午pretty的多处于亏损状态。

No exception is thrown and the program continues to execute without any changes except for the lack of volume. I've had a really hard time tracking down what conditions cause the error or recreating it after it happens. I can't find the error in the documentation anywhere and am pretty much at a loss.

任何帮助将是很大的AP preciated!

Any help would be greatly appreciated!

编辑:我忘了提,我加载的MP3文件,而不是OGG

I forgot to mention that I am loading mp3 files, not ogg.

推荐答案

我几乎此相同的问题,一些声音我试图加载和最近在玩。

i had almost this exact same problem with some sounds i was attempting to load and play recently.

我甚至把它弄坏了下来装载,是造成此错误的一个MP3。

i even broke it down to loading a single mp3 that was causing this error.

有一件事我注意到:当我满载-1的循环,它会用状态12错误而失败,但是当我装好了循环0次,它会成功。甚至试图加载1次失败。

one thing i noted: when i loaded with a loop of -1, it would fail with the "status 12" error, but when i loaded it to loop 0 times, it would succeed. even attempting to load 1 time failed.

最后的解决办法是在音频编辑器并重新编辑它打开MP3用稍小的质量,使文件现在更小,而且似乎没有占用相当尽可能多的资源在系统中。

the final solution was to open the mp3 in an audio editor and re-edit it with slightly lesser quality so that the file is now smaller, and doesn't seem to take up quite as many resources in the system.

最后,有这样的讨论,鼓励进行您所使用的对象释放,因为确实是有对能够使用的资源硬限制,它是全系统的,所以如果你使用多个的资源,其他应用程序将无法使用它们。

finally, there is this discussion that encourages performing a release on the objects you are using, because there is indeed a hard limit on the resources that can be used, and it is system-wide, so if you use several of the resources, other apps will not be able to use them.

https://groups.google.com/forum/#!topic/android-platform/tyITQ09vV3s/discussion%5B1-25%5D

有关音频,还有每32个活动AudioTrack对象的硬性限制   设备的(而不是每个应用程序:需要与休息制度分忧32),和AudioTrack在内部使用下面的Soundpool,   基于OpenSL ES等,但ToneGenerator,MediaPlayer的,原生音频   实际AudioTrack限制为< 32;它更多地取决于软因素   如存储器,CPU负载,等等还要注意的是,在限幅   Android的音频混音器目前不具备动态范围COM pression,   因此可以夹如果有大量活性声音   而且他们都响亮。

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), and AudioTrack is used internally beneath SoundPool, ToneGenerator, MediaPlayer, native audio based on OpenSL ES, etc. But the actual AudioTrack limit is < 32; it depends more on soft factors such as memory, CPU load, etc. Also note that the limiter in the Android audio mixer does not currently have dynamic range compression, so it is possible to clip if you have a large number of active sounds and they're all loud.

有关视频播放器的限制是非常低得多,由于激烈的负载   该视频放装置上。

For video players the limit is much much lower due to the intense load that video puts on the device.

我会以此为契机,提醒媒体开发者:请   记住调用发布()的媒体对象,当你的应用程序已暂停。   这样就减少了潜在的资源,其他应用程序将需要。   不要依赖于媒体对象被清理在敲定由   垃圾收集器,为具有非predictable时机。

I'll use this as an opportunity to remind media developers: please remember to call release() for media objects when your app is paused. This frees up the underlying resources that other apps will need. Don't rely on the media objects being cleaned up in finalize by the garbage collector, as that has unpredictable timing.