media player - Android: mediaplayer went away with unhandled events -
i need duration of audio file series of voice announcements need play app. have added audio files resources , play fine. sample code below works perfect intended purpose: return duration of audio files.
here code:
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 audio resource.");} return duration; }
here's weird thing. code called in main activity prepares set of audio instructions given test. there no errors within activity. second activity called, long string of errors on logcat.
03-07 13:23:43.820: i/actionlogger(21435): gentest_info_test #0 created. 03-07 13:23:43.830: i/actionlogger(21435): gentest_info_test #1 created. 03-07 13:23:43.840: i/actionlogger(21435): gentest_info_test #2 created. 03-07 13:23:43.850: i/actionlogger(21435): gentest_info_test #3 created. <snip> 03-07 13:23:43.910: i/actionlogger(21435): gentest_info_all tests created. 03-07 13:23:47.260: w/mediaplayer(21435): mediaplayer went away unhandled events 03-07 13:23:47.260: w/mediaplayer(21435): mediaplayer went away unhandled events 03-07 13:23:47.260: w/mediaplayer(21435): mediaplayer went away unhandled events 03-07 13:23:47.260: w/mediaplayer(21435): mediaplayer went away unhandled events 03-07 13:23:47.260: w/mediaplayer(21435): mediaplayer went away unhandled events 03-07 13:23:47.260: w/mediaplayer(21435): mediaplayer went away unhandled events 03-07 13:23:47.260: w/mediaplayer(21435): mediaplayer went away unhandled events 03-07 13:23:47.260: w/mediaplayer(21435): mediaplayer went away unhandled events 03-07 13:23:47.270: w/mediaplayer(21435): mediaplayer went away unhandled events <snip>
i've single-stepped upto end of main activity (no errors) , first line of second activity. errors thrown between activities.
also, if comment out 8 lines of try block (thus returning zero) logcat errors avoided. when restore 8 lines errors come back. i've dug through documentation , searched web, , believe correctly constructing, releasing , destroying mediaplayer object, can't see why getting error. said, must doing wrong. ideas?
thanks,
kevin
just put mp.reset();
before mp.release();
.
Comments
Post a Comment