My Android Advanced tour------>android mediarecorder.stop () error java.lang.RuntimeException:stop failed.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.