13.6 C
New York
Monday, October 13, 2025

android – LibGDX with SoundPool


I am creating a recreation for Android utilizing LibGDX in Android Studio.
I just lately came upon that some sounds in my recreation fail to play. I observed that each 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 couldn't create monitor, standing: -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 shopper; switch 4, monitor 44100 Hz, output 48000 Hz

That is the code I take advantage of to play the sounds:

public lengthy playSound(SFX fileName, boolean loop, float quantity, boolean randomPitch) {
        if (GameSettings.SOUND_TOGGLE) {
            strive {
                Sound sound = prepareSound(fileName);
                if (randomPitch && GameSettings.SOUND_RANDOM_PITCH) {
                    return setRandomPitch(loop, sound, quantity);
                }
                if (loop) {
                    return sound.loop(quantity);
                } else {
                    return sound.play(quantity);
                }
            } catch (GdxRuntimeException e) {
                e.printStackTrace();
            }
        }
        return -1;
    }
non-public Sound prepareSound(SFX soundFile) throws GdxRuntimeException {
        strive {
            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 = Major.getAssetsManager().get(soundPath, Sound.class);
                sounds.put(soundFile.getValue(), sound);
            } else {
                sound = sounds.get(soundFile.getValue());
            }
            if (sound == null) {
                throw new GdxRuntimeException("making ready sound failed - sound not discovered.");
            }
            return sound;
        } catch (GdxRuntimeException e) {
            throw e;
        }
    }

The sound information are in WAV format.
Any concepts learn how to repair it? Thanks upfront!

Replace: I’ve came upon that this drawback seems solely on my Nexus 5X. I attempted it on Xiaomi Redmi Word 4X and it did not occur.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles