I have a LibGdx game, where the user taps on the screen, and a Sound will play. When the user taps on the screen, a texture will "fire" another texture as a missile, and can hit a target, when this target "dies", another sound will play.
I use these two Sounds often in the game, Shooting Sound, and Hit Sound. When I load the game, everything works fine - the sound doesn't get an error when I load multiple instances of the Sound/Textures on level 1 - so it doesn't seem to be related to memory, because this error can appear when I use a lot less instances of sound/textures, but when I have loaded the "game screen" more times, it starts to appear.
The error is only related to two sound-files, one when the user taps the screen, and the other when the "target" dies. So it does only happen when I load Sounds a lot of times.
The problem only occurs when I go to higher levels, and load the game screen more times. I load the same game screen over and over, only with more instances of "targets".
Error:
W/SoundPool﹕ Sample was not loaded. Waiting for 30ms.
W/AudioTrack﹕ AUDIO_OUTPUT_FLAG_FAST denied by client
com.mygdx.game.android E/AudioTrack﹕ AudioFlinger could not create track, status: -12
com.mygdx.game.android E/SoundPool﹕ Error creating AudioTrack
I load my Sound like this:
Sound playDeadSound;
public void playDeadSound(){
soundDead = Gdx.audio.newSound(Gdx.files.internal("dead.ogg"));
soundDead.play();
soundDead.dispose();
}
Things I have tried
- To instantiate the Sound file in the create method, and then use the same object over and over.
- I have tried to call soundDead.resume(); instead of play(); to load the sound.
- I have tried to re-sample my audio to 48KHz, and to the lowest (which was around 5-8KHz IIRC).
- I have tried to start out with 40 targets, and I get no errors, and I have tried to start out with 5 targets, and errors start appearing when I go a few levels higher and the targets are 10-15.
- I have tried to remove all other sounds except one of the Sounds that creates the error (Shooting Sound/Hit Sound).
- I have tried to stop and then dispose the sound, and then create it when I call it.
- I have tried to have 2 sound files, and then call them one after another, so they doesn't get used at the same time.
The files are 5KB big each, and around 1 second long. Any ideas on what could cause this error? Thanks!
Solution:
The problem was that I reloaded the Sound over and over when I started a new level, hence why the problem never occured when I was at level 1. The problem got fixed when I used the same sound during the whole app's lifetime. A big thanks to Alesegdia for coming up with the answer.