I've recently added sounds into my LibGDX game. It's set up so that all the sounds I need are loaded into an AssetManager, and I retrieve them when I need to play them from a getSound(String name) method.
It works fine for a little bit when you play, but eventually it stops playing some, and sometimes most of them. I'd be fine with prioritizing the ones that are most recently played, and stopping the ones that are older if need be, but LibGDX doesn't seem to give you that much control over them.
The log error I get when this happens
E/AudioTrack: AudioFlinger could not create track, status: -12
E/SoundPool: Error creating AudioTrack.
It's usually playing quite a few at one time, probably around 10-20 small sounds at one time, depending on the situation, so I'm pretty sure that's the problem. I've read here about releasing a sound once it's played using a SoundPool, but I'm not entirely sure how to do that with LibGDX, or if it's possible, because I didn't see a class like that when I looked.
Also, I'm using ogg files for all of the sounds and none of them are very big. Thanks!
Solved! By creating my own (kind of pseudo)
Soundclass, and a loader for it to be used with anAssetManagerusingassetManager.setLoader(). In the customSoundclass, I set every sound to keep track of theirsoundIds in anArray<Long>, then every time it plays I check the size of the array against alimitvariable, stopping the oldest sound in the array. 0 meaning only able to be played one at a time, up to as far as I decide is necessary. This might not be a perfect solution, but it seems to work fairly well.Criticism is welcome.
My created "
Sound" class:MySoundLoaderclass, forAssetManager: