0

I am creating a game using Libgdx. I have a lot of small sounds files in the MP3-format and since it is so many I do not preload them. I only load the sound I want to play when it is to be used, like this:

actorSound = Gdx.audio.newSound(Gdx.files.internal(sound));

The code above works great, but the rest of my sounds do not unfortunately. The actor above has its own class and plays a different sound every time it is touched.

When I try to play sounds in my Gamescreen I get the following error:

AUDIO_OUTPUT_FLAG_FAST denied by client

All the audiofiles have the same properties and have been recorded using the same microphone & Audacity. The files are all 44100Hz and only a few kb in size each.

I wonder why the sounds the Actor plays work and the other sounds do not?

I decided to try to change the non-working sounds to music instead and now they play fine - for a little while that is. I can play a full game, return to the menu and start a new game again. The second time I start a game I only get 3 sounds from the Gamescreen and then it is silent except for the sounds from the actor. The error that appears looks like this:

E/MediaPlayer: Error (1,-19)

I load the Music just the same way as the Sound:

gameSound = Gdx.audio.newMusic(Gdx.files.internal(soundeffect));

I have looked into the two errors by reading posts like these:

AUDIO_OUTPUT_FLAG_FAST denied by client

Mediaplayer error (-19,0) after repeated plays

But I'm not sure what to do or change to solve my problem. I would prefer Sound if that is possible, but Music is an acceptable workaround...

When it comes to Music it is probably as suggested in the URL, that I do not release the media players. I am not sure how to do that?

When I leave the GameScreen for another screen, like the MenuScreen or RewardScreen, I dispose Music first. The other screens use Music as well and the sounds are loaded when needed. When I change back to the GameScreen I dispose again and then start a new game...

Any ideas or suggestions? Any help is greatly appreciated.

I added AssetManager as suggested, and I now have a loding screen that loads all the sounds. I load them as sounds and not music, which is how I prefer it.

The sounds work well in the actual game but once I get to the reward screen, only the first sound plays and after that the app crashes with the following error:

06-02 07:47:09.774 6208-6282E/AndroidRuntime: FATAL EXCEPTION: GLThread 2935

Process: PID: 6208

java.lang.NullPointerException: Attempt to read from field 'com.badlogic.gdx.assets.AssetManager 
Assets.Assets.manager' on a null object reference
at DelayedSounds(RewardsScreen.java:538)  
at RewardsScreen.Update(RewardsScreen.java:567)
at Screens.RewardsScreen.render(RewardsScreen.java:577)
at Game.render(Game.java:46)
at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:459)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1562)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1262)
06-02 07:47:13.823 6208-6208 E/AndroidGraphics: waiting for pause 
synchronization took too long; assuming deadlock and killing

The DelayedSounds method looks like this:

    public void DelayedSounds(){
    timer = timer + Gdx.graphics.getDeltaTime();
    if(playitem == true && timer > 2){
        itemsound = "vinster/" + item + ".mp3";
        assets.manager.get(itemsound, Sound.class).play(volume);
        //sound = Gdx.audio.newMusic(Gdx.files.internal(itemsound));
        //sound.setVolume(volume);
        //sound.play();
        playitem = false;
    }
    if(playkeep == true && time > 3){
        assets.manager.get("dialog/VINSTEN.mp3", Sound.class).play(volume);
        //sound = Gdx.audio.newMusic(Gdx.files.internal("prizes/prize.mp3"));
        //sound.setVolume(volume);
        //sound.play();
        playkeep = false;
    }
}

As can be seen I use AssetManager now, and have commented out my old code for testing purposes. I define AssetManager in my main class and then pass it around to all other classes that uses sounds. The RewardsScreen will only play the first sound and then it crashes on a NULL object reference as it seems.

If I change my code back to using Music in the RewardsScreen it works fine (see the code that is commmented out)

The sound I try to play is exactly the same in both cases. Assets class that handles the loading of all my assets has the sounds included and since I still get a NULL object I assume one or more items fails to load?

I search the logs and find this where it loads the sounds:

06-02 08:05:09.360 9844-9888/E/WVMExtractor: Failed to open libwvm.so: dlopen failed: library "libwvm.so" not found
06-02 08:05:09.395 9844-9888/ E/NdkMediaExtractor: sf error code: -1010
06-02 08:05:09.395 9844-9888/ E/SoundPool: Unable to load sample

Maybe this is related to my problem? I load all the sounds in the same manner and most definitely seem to work, the loading is the regular:

    manager.load("prizes/cash.mp3", Sound.class);

I still find the AUDIO_OUTPUT_FLAG_FAST denied by client in my logs but now the sounds are playing instead of being rejected.

Any more ideas about how to solve this?

1 Answer 1

0

Your link having enough information for your bug.

It's not good way to create Resource instance each time in Game, Create once and user All over your game, if possible use AssetManager.

Like create Music instance in onCreate() method of your game.

gameSound = Gdx.audio.newMusic(Gdx.files.internal(soundeffect));

Music having play(), resume() and many other helpful methods.

You can also take a look of this, it may be helpful.

2
  • Thanks for your reply. I have added a loading screen to my app that loads all the sounds that also has a progress bar. It takes a little while so I would have preferred another option, but I am willing to give this a proper try. I still get errors unfortunately though, some things seem to work better but surely not everything. I will update my question with more information.
    – Arnulf
    Jun 2, 2017 at 5:36
  • It seems to work now finally, using AssetManager. I made a method that played through each and every sound in my app. I found a small number that refused to load so I recorded them again and now it works fine. I also noticed in one of my screens that I had forgotten to add "this.assets = assets". There is still a warning about the AUDIO_OUTPUT_FLAG, but I can live with that as long as the sound is playing.
    – Arnulf
    Jun 4, 2017 at 18:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.