BaradRupgithub / libgdx

Automatically exported from code.google.com/p/libgdx
0 stars 0 forks source link

Error when exiting application (AndroidMusic.isPlaying) #178

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
Exiting an application on Android using the [Back] button sometimes displays an 
error dialog (force-close dialog). The error occurs trying to close the music 
player.

What is the expected output? What do you see instead?
There should be no error.

What version of the product are you using? On what operating system?
Android 2.3.3, LibGDX 0.9.0.

Suggested solution:
It appears the audio player crashes trying to stop the music player. As the 
application is exiting anyway, I recommend to add a try/catch in 
"AndroidMusic.isPlaying" and simply log the exception instead of throwing it. 

Stacktrace:
03-11 15:17:09.398: ERROR/AndroidRuntime(15593): FATAL EXCEPTION: main
03-11 15:17:09.398: ERROR/AndroidRuntime(15593): java.lang.RuntimeException: 
Unable to pause activity 
{com.campussaga.android.lite/com.campussaga.androidlib.MainActivity}: 
java.lang.IllegalStateException
03-11 15:17:09.398: ERROR/AndroidRuntime(15593):     at 
android.app.ActivityThread.performPauseActivity(ActivityThread.java:2354)
03-11 15:17:09.398: ERROR/AndroidRuntime(15593):     at 
android.app.ActivityThread.performPauseActivity(ActivityThread.java:2311)
03-11 15:17:09.398: ERROR/AndroidRuntime(15593):     at 
android.app.ActivityThread.handlePauseActivity(ActivityThread.java:2291)
03-11 15:17:09.398: ERROR/AndroidRuntime(15593):     at 
android.app.ActivityThread.access$1700(ActivityThread.java:117)
03-11 15:17:09.398: ERROR/AndroidRuntime(15593):     at 
android.app.ActivityThread$H.handleMessage(ActivityThread.java:942)
03-11 15:17:09.398: ERROR/AndroidRuntime(15593):     at 
android.os.Handler.dispatchMessage(Handler.java:99)
03-11 15:17:09.398: ERROR/AndroidRuntime(15593):     at 
android.os.Looper.loop(Looper.java:123)
03-11 15:17:09.398: ERROR/AndroidRuntime(15593):     at 
android.app.ActivityThread.main(ActivityThread.java:3683)
03-11 15:17:09.398: ERROR/AndroidRuntime(15593):     at 
java.lang.reflect.Method.invokeNative(Native Method)
03-11 15:17:09.398: ERROR/AndroidRuntime(15593):     at 
java.lang.reflect.Method.invoke(Method.java:507)
03-11 15:17:09.398: ERROR/AndroidRuntime(15593):     at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-11 15:17:09.398: ERROR/AndroidRuntime(15593):     at 
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-11 15:17:09.398: ERROR/AndroidRuntime(15593):     at 
dalvik.system.NativeStart.main(Native Method)
03-11 15:17:09.398: ERROR/AndroidRuntime(15593): Caused by: 
java.lang.IllegalStateException
03-11 15:17:09.398: ERROR/AndroidRuntime(15593):     at 
android.media.MediaPlayer.isPlaying(Native Method)
03-11 15:17:09.398: ERROR/AndroidRuntime(15593):     at 
com.badlogic.gdx.backends.android.AndroidMusic.isPlaying(AndroidMusic.java:43)
03-11 15:17:09.398: ERROR/AndroidRuntime(15593):     at 
com.badlogic.gdx.backends.android.AndroidAudio.pause(AndroidAudio.java:57)
03-11 15:17:09.398: ERROR/AndroidRuntime(15593):     at 
com.badlogic.gdx.backends.android.AndroidApplication.onPause(AndroidApplication.
java:171)
03-11 15:17:09.398: ERROR/AndroidRuntime(15593):     at 
android.app.Activity.performPause(Activity.java:3851)
03-11 15:17:09.398: ERROR/AndroidRuntime(15593):     at 
android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1191)
03-11 15:17:09.398: ERROR/AndroidRuntime(15593):     at 
android.app.ActivityThread.performPauseActivity(ActivityThread.java:2341)
03-11 15:17:09.398: ERROR/AndroidRuntime(15593):     ... 12 more

Original issue reported on code.google.com by xtophena...@gmail.com on 11 Mar 2011 at 2:26

GoogleCodeExporter commented 9 years ago
Thanks for reporting this. I wonder what's happening here. I'll add the 
quick-fix but investigate the real cause for this. It's an indication that the 
Mediaplayer instance has been diposed before, which is strange because we guard 
against that.

Original comment by badlogicgames on 11 Mar 2011 at 2:29

GoogleCodeExporter commented 9 years ago
I also tried to reproduce this but had no luck. If you have a reproduceable 
test case i'd be grateful.

Original comment by badlogicgames on 11 Mar 2011 at 2:29

GoogleCodeExporter commented 9 years ago
Ok, i added the temporary fix. Will try to come up with a clean solution once i 
can identify the problem. 

Original comment by badlogicgames on 11 Mar 2011 at 2:36

GoogleCodeExporter commented 9 years ago
Ohh, nm. I already fixed that issue. We'll release 0.91 after letting a few 
more bug reports trickle in. For now you can solve your issue by using the 
latest nightlies.

Original comment by badlogicgames on 11 Mar 2011 at 2:38

GoogleCodeExporter commented 9 years ago
There isn't much to reproduce. Also, it only happens sometimes and only when 
the application is terminated on Android. 

I am looping music in the background. It is possible that the music is 
terminated twice once by my code and once by the Activity finish function. It's 
no big deal, it just looks ugly if there is a force-close error closing the 
application.

That's what I am using: com.badlogic.gdx.audio.Music

Original comment by xtophena...@gmail.com on 11 Mar 2011 at 2:51