Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MediaPlayer TimeoutException

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.

like image 661
jessetvogel Avatar asked Jan 03 '14 20:01

jessetvogel


2 Answers

Call MediaPlayer.release() in your code (eg. in Activity.onPause()). It will cause to do less work in MediaPlayer.finalize() and exception should disappear.

like image 194
darken K Avatar answered Oct 12 '22 17:10

darken K


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);
like image 40
Force Avatar answered Oct 12 '22 15:10

Force