MediaPlayer TimeoutException

4.5k Views Asked by At

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.

4

There are 4 best solutions below

0
On

I think mediaserver process on the client has crashed.

0
On

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);
0
On

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

0
On

Some thoughts:

  • Did you locate which thread is doing this? It does seem that its not the main UI thread and you should be able to catch that exception.
  • Like the previous answer you should really consider rethinking when you release your player.
  • One Error I am still facing is with the audioflinger service. It causes all running media players to go into error state (handled with error code (100, 0)). Player goes into error state and am not being able to resume the way it was