I have made an Android app and now it's on Google Play. But now someone reported a Crash, and the stacktrace said the following:
java.util.concurrent.TimeoutException: android.media.MediaPlayer.finalize() timed out after 10 seconds
at android.media.MediaPlayer.native_finalize(Native Method)
at android.media.MediaPlayer.finalize(MediaPlayer.java:1960)
at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:187)
at java.lang.Daemons$FinalizerDaemon.run(Daemons.java:170)
at java.lang.Thread.run(Thread.java:856)
And there is no sign of some code from one of my packages. I do use the MediaPlayer class. Anyone who can help me out here?
Jesse.
Call MediaPlayer.release()
in your code (eg. in Activity.onPause()
). It will cause to do less work in MediaPlayer.finalize()
and exception should disappear.
To catch this error you can implement a android.media.MediaPlayer.OnErrorListener in your Fragment or Activity.
/*
* Called to indicate an error. Parameters
*
* mp the MediaPlayer the error pertains to what the type of error that has
* occurred: MEDIA_ERROR_UNKNOWN MEDIA_ERROR_SERVER_DIED extra an extra
* code, specific to the error. Typically implementation dependant. Returns
* True if the method handled the error, false if it didn't. Returning
* false, or not having an OnErrorListener at all, will cause the
* OnCompletionListener to be called.
*/
@Override
public boolean onError(MediaPlayer mp, int what, int extras) {
return true;
}
When you create your MediaPlayer make sure you call
mediaPlayer.setOnErrorListener(this);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With