多媒体播放器超时异常

12

我制作了一款 Android 应用,并将其上架至 Google Play。 但是现在有人报告发生了崩溃,堆栈跟踪显示如下:

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)

我的一个程序包中的某些代码没有出现任何迹象。我确实使用了MediaPlayer类。有谁能在这里帮帮我吗?

Jesse。

4个回答

5

在您的代码中调用 MediaPlayer.release() (例如在 Activity.onPause() 中)。这将导致在 MediaPlayer.finalize() 中执行较少的工作,异常应该消失。


1
为了捕捉这个错误,你可以在你的Fragment或Activity中实现一个android.media.MediaPlayer.OnErrorListener。
/*
     * 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;
    }

当您创建MediaPlayer时,请确保调用此方法。
mediaPlayer.setOnErrorListener(this);

0

一些想法:

  • 你找到是哪个线程在执行这个操作了吗?看起来不像是主UI线程,你应该能够捕获到异常。
  • 和之前的答案一样,你真的应该考虑重新思考何时释放你的播放器。
  • 我仍然遇到一个问题,就是与audioflinger服务有关。它会导致所有正在运行的媒体播放器进入错误状态(使用错误代码(100, 0)处理)。播放器进入错误状态,我无法恢复到原来的状态。

-1

我认为客户端的mediaserver进程已经崩溃了。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接