0

The problem

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.

I have tried..

So far I have tried almost every way of loading resources. I have used:

Attempt 1

public class MyGame extends ApplicationAdapter {
    Music song;

    ...

    @Override
    public void create() {
        song = Gdx.audio.newMusic(Gdx.files.internal("song.mp3"));
        song.play();
        ...
    }
}

Attempt 2

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()
    }
}

Attempt 3

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.

Other things of note:

  • I am trying to load a song that is a little more than 3MB.
  • I tried having the song in the assets folder, as well as in a assets/snd folder
  • Is it possible to get a live debugger for debugging on android, or see some sort of traceback for any possible errors?

Thanks

natebot13
  • 167
  • 3
  • 11
  • There should be some stacktrace logged in the logcat – donfuxx Jun 13 '14 at 21:46
  • @don And where would that be? Sorry, I'm new to android development and libgdx. – natebot13 Jun 13 '14 at 21:53
  • for example here it is explained: http://stackoverflow.com/a/23353174/2399024 – donfuxx Jun 13 '14 at 22:10
  • I am having issues with getting a stack trace. I'm using NetBeans, and (due to a graphical problem) am using the command line to install to my android device with: `gradlew.bat android:installDebug android:run` – natebot13 Jun 13 '14 at 23:26

1 Answers1

1

Answer

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...

natebot13
  • 167
  • 3
  • 11
  • You know what would be really handy? actually telling us the bitrate, hz etc. that works. The libgdx help sure doesn't give any clues. – Nick.Mc Dec 27 '15 at 13:09
  • Once I popped it into Audacity and exported it as an mp3, it worked fine, no matter what rate it was at. I think the original file had something weird with it, and simply by exporting it through Audacity, the problem was knocked off. Hope that helps! – natebot13 Dec 27 '15 at 13:15
  • Thanks for coming back. I did exactly the same - exported mp3 from audacity. I just get a very unhelpful 'Asset not loaded' message in the console. Devoid of any other clues. Wrong path? too big? who knows! – Nick.Mc Dec 27 '15 at 13:23
  • In the end I found that example 2 worked fine but example 3 returned "Asset not Loaded" – Nick.Mc Dec 28 '15 at 03:24