MediaPlayer TimeoutException
Asked Answered
U

4

12

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.

Understanding answered 3/1, 2014 at 20:47 Comment(0)
S
5

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

Shaylashaylah answered 6/2, 2015 at 9:59 Comment(0)
D
1

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);
Drye answered 30/5, 2017 at 16:27 Comment(0)
S
0

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
Signe answered 28/10, 2015 at 7:8 Comment(0)
R
-1

I think mediaserver process on the client has crashed.

Romy answered 3/1, 2014 at 21:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.