Android:mediaplayer带走了未处理的事件

我需要获取audio文件的持续时间,以便从应用程序播放一系列语音通知。 我已经添加了audio文件作为资源,他们打得很好。 下面的示例代码实际上完美地达到了预期的目的:它确实会返回audio文件的持续时间。

这里是代码:

float getDurationOfAudioResource(LocationEnum loc, Context context){ float duration = 0; try { MediaPlayer mp; mp = MediaPlayer.create(context, getAudioResource(loc)); duration = mp.getDuration(); mp.release(); mp = null; } catch (IllegalStateException e) {e.printStackTrace(); logError(25, "TestDescItem:Fault::Could not open mediaplayer object with audio resource.");} return duration; } 

这是奇怪的事情。 此代码在主要活动中调用,为给定testing准备一组audio指令。 此活动中没有错误。 但是一旦第二个活动被调用,我就会在logcat上遇到很长的一串错误。

 03-07 13:23:43.820: I/ActionLogger(21435): GenTest_Info_Test #0 successfully created. 03-07 13:23:43.830: I/ActionLogger(21435): GenTest_Info_Test #1 successfully created. 03-07 13:23:43.840: I/ActionLogger(21435): GenTest_Info_Test #2 successfully created. 03-07 13:23:43.850: I/ActionLogger(21435): GenTest_Info_Test #3 successfully created. <snip> 03-07 13:23:43.910: I/ActionLogger(21435): GenTest_Info_all tests successfully created. 03-07 13:23:47.260: W/MediaPlayer(21435): mediaplayer went away with unhandled events 03-07 13:23:47.260: W/MediaPlayer(21435): mediaplayer went away with unhandled events 03-07 13:23:47.260: W/MediaPlayer(21435): mediaplayer went away with unhandled events 03-07 13:23:47.260: W/MediaPlayer(21435): mediaplayer went away with unhandled events 03-07 13:23:47.260: W/MediaPlayer(21435): mediaplayer went away with unhandled events 03-07 13:23:47.260: W/MediaPlayer(21435): mediaplayer went away with unhandled events 03-07 13:23:47.260: W/MediaPlayer(21435): mediaplayer went away with unhandled events 03-07 13:23:47.260: W/MediaPlayer(21435): mediaplayer went away with unhandled events 03-07 13:23:47.270: W/MediaPlayer(21435): mediaplayer went away with unhandled events <snip> 

我已经单步走到主要活动(没有错误)的结尾,从第二个活动的第一行开始。 这些错误肯定是在这些活动之间引发的。
另外,如果我注释掉try块的8行(因此只返回0),logcat错误就被避免了。 当我恢复八条线时,错误又回来了。 我已经通过文档挖掘和searchnetworking,我相信我正确构build,释放和销毁mediaplayer对象,所以我不明白为什么我得到一个错误。 这就是说,我一定在做错事。 有任何想法吗?

谢谢,

凯文