Reputation: 416
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
Upvotes: 3
Views: 6823
Reputation: 961
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();
Upvotes: 0
Reputation: 29
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.
Upvotes: 0
Reputation: 1668
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.
Upvotes: 4