0
\$\begingroup\$

Problem solved with music = Gdx.audio.newMusic(Gdx.files.internal("song.mp3"));

I am looking for music implementation in my app with LibGDX. I saw the guide provided in LibGDX documentation but it doesn't work for me and this is my code :

public class GameScreen implements Screen {

    Music music;
    public GameScreen(MyGdxGame game)   {

        music = Gdx.audio.newMusic(Gdx.files.local("assets/song.mp3"));
        music.play();

    }

When I run my code it returns me this error :

    at com.badlogic.gdx.backends.android.AndroidAudio.newMusic(AndroidAudio.java:124)
            at GameScreen.<init>(GameScreen.java:62)
            at FirstScreen.render(FirstScreen.java:99)
            at com.badlogic.gdx.Game.render(Game.java:46)
            at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:422)
            at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1522)
            at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1239)
05-22 20:49:06.213  15534-15534/  E/SysUtils﹕ ApplicationContext is null in ApplicationStatus
05-22 20:49:09.358  15534-15572/ E/MediaPlayer-JNI﹕ QCMediaPlayer mediaplayer NOT present
05-22 20:49:09.374  15534-15572/ E/AndroidRuntime﹕ FATAL EXCEPTION: GLThread 10072

com.badlogic.gdx.utils.GdxRuntimeException: Error loading audio file: assets/song.mp3
            at com.badlogic.gdx.backends.android.AndroidAudio.newMusic(AndroidAudio.java:132)
            at .GameScreen.<init>(GameScreen.java:62)
            at .game.FirstScreen.render(FirstScreen.java:99)
            at com.badlogic.gdx.Game.render(Game.java:46)
            at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:422)
            at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1522)
            at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1239)
     Caused by: java.io.IOException: setDataSource failed.
            at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1076)
            at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1022)
            at com.badlogic.gdx.backends.android.AndroidAudio.newMusic(AndroidAudio.java:124)
            at .game.GameScreen.<init>(GameScreen.java:62)
            at .game.FirstScreen.render(FirstScreen.java:99)
            at com.badlogic.gdx.Game.render(Game.java:46)
            at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:422)
            at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1522)
            at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1239)
\$\endgroup\$
  • \$\begingroup\$ Is the GameScreen being instantiated in your ApplicationAdapter's create() method? If you're not sure what I mean, please post the method in which you instantiate the GameScreen. \$\endgroup\$ – StrongJoshua May 22 '15 at 20:30
  • \$\begingroup\$ @StrongJoshua Yes it is instantiated in my create method but I extend Game and not ApplicationAdapter \$\endgroup\$ – user65825 May 22 '15 at 21:06
  • \$\begingroup\$ Hm I don't know, this might be better asked in the LibGdx forums. \$\endgroup\$ – StrongJoshua May 22 '15 at 21:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.