【问题标题】:MediaPlayer TimeoutException媒体播放器超时异常
【发布时间】:2014-01-03 20:47:26
【问题描述】:

我制作了一个 Android 应用,现在它在 Google Play 上。 但是现在有人报告了一个 Crash,stacktrace 说如下:

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 类。 有谁能帮帮我吗?

杰西。

【问题讨论】:

    标签: java android android-mediaplayer timeoutexception


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      要捕获此错误,您可以在 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);
      

      【讨论】:

        【解决方案3】:

        一些想法:

        • 您是否找到了执行此操作的线程?它似乎不是主 UI 线程,你应该能够 捕获该异常。
        • 与之前的 answer 一样,您应该在发布播放器时真正考虑重新考虑。
        • 我仍然面临的一个错误是 audioflinger 服务。它会导致所有正在运行的媒体播放器进入错误状态(使用错误代码 (100, 0) 处理)。播放器进入错误状态,无法恢复原状

        【讨论】:

          【解决方案4】:

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

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2012-01-22
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多