Home Game Development android – LibGDX with SoundPool

android – LibGDX with SoundPool

0
android – LibGDX with SoundPool

[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]

Previous article New Mass Effect Game Teasers Released on N7 Day
Next article Pay $32 for a brand-new full-size HyperX mechanical keyboard
Hello there! My name is YoleeTeam, and I am thrilled to welcome you to AmazonianGames.com. As the premier destination for all things related to Amazon Games' universe, we are dedicated to providing you with the most exciting and immersive gaming experiences out there. From captivating visuals to exhilarating gameplay, our website is packed with comprehensive insights, updates, and reviews to keep you ahead of the game. Whether you're a seasoned gamer or new to the scene, I am here to guide you through this virtual frontier. If you have any questions or suggestions, feel free to reach out to me at john@yoleesolutions.com. Embark on your Amazon gaming journey today with AmazonianGames.com and let the adventure begin!