Reputation: 187
I'm having difficulty loading a song for a little android game practice I'm trying to create. All the graphics and rendering works perfectly, and downloading that to my android tablet works great and displays great. However, when I try to add some background music, the app freezes with a black screen when it attempts to start, and then simply closes with a, "Unfortunately, appname has stopped" dialog error.
So far I have tried almost every way of loading resources. I have used:
public class MyGame extends ApplicationAdapter {
Music song;
...
@Override
public void create() {
song = Gdx.audio.newMusic(Gdx.files.internal("song.mp3"));
song.play();
...
}
}
public class Audio {
Music song;
public Audio() {
song = Gdx.audio.newMusic(Gdx.files.internal("song.mp3"));
song.play();
}
}
public class MyGame extends ApplicationAdapter {
Audio Song; //Custom Class
...
@Override
public void create() {
song = new Audio()
}
}
public class MyGame extends ApplicationAdapter {
AssetManager manager;
...
@override
public void create() {
manager = new AssetManager();
manager.load("song.mp3", Music.class);
...
manager.finishLoading();
Music song = manager.get("snd/Of the Airship Academy.mp3", Music.class);
song.play();
}
}
All of these work perfectly when running the desktop version, but when downloading to my android device, the app fails and stops.
assets
folder, as well as in a assets/snd
folderThanks
Upvotes: 0
Views: 525
Reputation: 187
So, for anyone having the same problem, I figured I'd share how I fixed it. I discovered that the music Hz for the song I was using was incompatible with the music loader for libgdx. I ended up popping my song into Audacity and saving different versions of it with different project rates. Once that was done, the file loaded and played like normal on my android tablet.
Bottom line: Be sure the bitrate of your music is compatible with the music loader you're using. Took forever to figure this out...
Upvotes: 1