Today in Call Mediarecorder.stop (), error, Java.lang.RuntimeException:stop failed.
E/androidruntime (7698): Cause by:java.lang.RuntimeException:stop failed. E/androidruntime (7698): at android.media.MediaRecorder.stop (Native Method), E/androidruntime (7698): at Com.tintele.sos.VideoRecordService.stopRecord (videorecordservice.java:298)
The error code is as follows:
if (Mediarecorder! = null) {mediarecorder.stop (); Mediarecorder.release (); mediarecorder = Null;if (Mcamera! = null) { Mcamera.release (); mcamera = null;}}
The Stop () method source code is as follows:
/** * Stops recording. Call the After start (). Once recording is stopped, * you'll have the configure it again as if it has just been constructed. * Note that a runtimeexception are intentionally thrown to the * application, if no valid Audio/video data have been rec Eived when the Stop () * is called. This happens if stop () was called immediately after * Start (). The failure lets the application take action accordingly to * clean up the output file (delete the output file, Stance), since * The output file is not properly constructed if this happens. * * @throws illegalstateexception if it is called before start () */public native void Stop () throws illegal Stateexception;
The source code says: Note that a runtimeexception was intentionally thrown to the application, if no valid Audio/video data have been rece ived when Stop () is called. This happens if stop () was called immediately after start ().
Now, in Mediarecorder.stop (); This sentence is wrong, now in Mediarecorder.stop (); This sentence will not be an error if you add a few words.
Mediarecorder.setonerrorlistener (NULL);
Mediarecorder.setoninfolistener (NULL);
Mediarecorder.setpreviewdisplay (NULL);
The following code is changed:
if (Mediarecorder! = null) {//added by Ouyang Starttry {///The following three parameters must be added, without adding the words will be dashed in mediarecorder.stop ();/ The error is: Runtimeexception:stop failedmediarecorder.setonerrorlistener (null); Mediarecorder.setoninfolistener (null); Mediarecorder.setpreviewdisplay (null); Mediarecorder.stop ();} catch (IllegalStateException e) {//Todo:handle exceptionlog.i ("Exception", Log.getstacktracestring (e));} catch (RuntimeException e) {//Todo:handle exceptionlog.i ("Exception", Log.getstacktracestring (e));} catch (Exception e) {//Todo:handle exceptionlog.i ("Exception", Log.getstacktracestring (e));} Added by Ouyang Endmediarecorder.release (); mediarecorder = Null;if (Mcamera! = null) {mcamera.release (); mcamera = null; }}
====================================================================================
Ouyangpeng welcome reprint, sharing with people is the source of progress!
Reprint please keep the original address : Http://blog.csdn.net/ouyang_peng
====================================================================================
Copyright NOTICE: This article is Ouyangpeng original article, welcome reprint, reprint please indicate source Http://blog.csdn.net/ouyang_peng
My Android Advanced tour------>android mediarecorder.stop () error java.lang.RuntimeException:stop failed.