3
votes

I'm attempting to simply load a Music asset using libgdx, and this is what I have:

Music main_background;
main_background = Gdx.audio.newMusic(Gdx.files.internal("data/music/main_bg.wav"));

This code is exactly the same code as they have in the small tutorial of "Making a game" with libgdx, and I'm trying to load my own sound that I have made (Using GarageBand, in case that matters). Whenever I try running this as a Desktop application, I get a bunch of errors:

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Error creating music com.badlogic.gdx.backends.openal.Wav$Music for file: data/music/main_bg.wav

Caused by: java.lang.reflect.InvocationTargetException

Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Error reading WAV file: data/music/main_bg.wav

Caused by: com.badlogic.gdx.utils.GdxRuntimeException: RIFF header not found: data/music/main_bg.wav

I'm not sure what the problem could be, because the audio file isn't corrupt (because I can listen to it perfectly fine) yet I can't find information anywhere about people getting this type of error when loading an asset.

I have a bunch of Texture's loaded just fine, but for some unknown reason I can't load a Music asset (and for the record, I tried loading the same file as a Sound asset and get essentially the same error).

Has anyone come across this before or have any ideas on what could be wrong?

EDIT: I should mention I also get this error if I try loading an mp3 or ogg file as well, it doesn't just happen with a wav

3
Are there any other GDX log messages in the console? Maybe something about OpenAL? Also, what platform is your desktop? Do you get a different error if the file doesn't exist at all (e.g., like "data/music/gibberish.wav")P.T.
I just tried to run my small game including the music today, and now it worked. I'm unsure what the problem was still, because I didn't change anything at all (I didn't even close and reopen Eclispe), and I had refreshed the asset directory multiple times because I thought it didn't know it existed.Ninjalemon

3 Answers

4
votes

First of all, know the differences between Sound and Music in libGdx. Read this: https://code.google.com/p/libgdx/wiki/Audio
The problem maybe is in bit rate. I had this problem and I changed the bitrate of wav files to 705kbps and it worked.

0
votes

I had the same issue. It was solved by restarting Eclipse. It seems some SDK files had not fully installed yet and restarting Eclipse allowed them to complete the install.

0
votes

You can convert it to .ogg, it occupies less space. And keep it in your data folder. Then declare a variable named music:

Music music;

After that in your create method:

music = Gdx.audio.newMusic(Gdx.files.internal("data/whoo.ogg"));

Then use it anywhere in your game - in render, touchUp touchDown anywhere you want the music:

music.play();