[ad_1]
I’m developing a game for Android using LibGDX in Android Studio.
I recently found out that some sounds in my game fail to play. I noticed that every time a sound fails to play, these are the logs:
04-12 10:49:51.784 24234-24283/com.gadarts.parashoot.android E/AudioTrack: AudioFlinger could not create track, status: -12
04-12 10:49:51.785 24234-24283/com.gadarts.parashoot.android E/SoundPool: Error creating AudioTrack
04-12 10:49:52.503 24234-24283/com.gadarts.parashoot.android W/AudioTrack: AUDIO_OUTPUT_FLAG_FAST denied by client; transfer 4, track 44100 Hz, output 48000 Hz
This is the code I use to play the sounds:
public long playSound(SFX fileName, boolean loop, float volume, boolean randomPitch) {
if (GameSettings.SOUND_TOGGLE) {
try {
Sound sound = prepareSound(fileName);
if (randomPitch && GameSettings.SOUND_RANDOM_PITCH) {
return setRandomPitch(loop, sound, volume);
}
if (loop) {
return sound.loop(volume);
} else {
return sound.play(volume);
}
} catch (GdxRuntimeException e) {
e.printStackTrace();
}
}
return -1;
}
private Sound prepareSound(SFX soundFile) throws GdxRuntimeException {
try {
String soundPath = SFX.fileAttribute.SFX_FOLDER_NAME.getValue() + "https://gamedev.stackexchange.com/" + SFX.fileAttribute.SOUNDS_FOLDER_NAME.getValue() + "https://gamedev.stackexchange.com/" + soundFile.getParentDir().getValue() + "https://gamedev.stackexchange.com/" + soundFile.getValue() + "." + soundFile.getFormat().getValue();
Sound sound;
if (!sounds.containsKey(soundFile.getValue())) {
sound = Main.getAssetsManager().get(soundPath, Sound.class);
sounds.put(soundFile.getValue(), sound);
} else {
sound = sounds.get(soundFile.getValue());
}
if (sound == null) {
throw new GdxRuntimeException("preparing sound failed - sound not found.");
}
return sound;
} catch (GdxRuntimeException e) {
throw e;
}
}
The sound files are in WAV format.
Any ideas how to fix it? Thanks in advance!
Update: I’ve found out that this problem appears only on my Nexus 5X. I tried it on Xiaomi Redmi Note 4X and it didn’t happen.
[ad_2]