Specific performance:
Call Mediarecorder's start () and stop () interval cannot be less than 1 seconds (sometimes more than 1 seconds), otherwise it will collapse.
Error message:
Java.lang.RuntimeException:stop failed.
At Android.media.MediaRecorder.stop (Native method)
Solution:
Call Setonerrorlistener (null) before stop; it's OK!
Related code:
/** Start recording/@Override public MediaPart Startrecord () {if (Mmediaobject!= null && msurfaceholder!= nul
L &&!mrecording) {MediaPart result = Mmediaobject.buildmediapart (Mcameraid, ". mp4");
try {if (Mmediarecorder = = null) {Mmediarecorder = new Mediarecorder ();
Mmediarecorder.setonerrorlistener (this);
else {mmediarecorder.reset ();
}//step 1:unlock and set camera to Mediarecorder Camera.unlock ();
Mmediarecorder.setcamera (camera);
Mmediarecorder.setpreviewdisplay (Msurfaceholder.getsurface ());
Step 2:set sources Mmediarecorder.setvideosource (MediaRecorder.VideoSource.CAMERA)//before Setoutputformat () Mmediarecorder.setaudiosource (MediaRecorder.AudioSource.MIC);//before Setoutputformat () mmediarecorder.se
Toutputformat (MediaRecorder.OutputFormat.MPEG_4); Set the format and encoding of the video output camcorderprofile mprofile = CamcorDerprofile.get (camcorderprofile.quality_480p);
Mmediarecorder.setprofile (Mprofile); Mmediarecorder.setvideosize (640),//after Setvideosource (), after Setoutformat () Mmediarecorder.setaudioencodin
Gbitrate (44100);
if (Mprofile.videobitrate > 2 * 1024 * 1024) mmediarecorder.setvideoencodingbitrate (2 * 1024 * 1024);
else Mmediarecorder.setvideoencodingbitrate (mprofile.videobitrate); Mmediarecorder.setvideoframerate (mprofile.videoframerate);//after Setvideosource (), after SetOutFormat () MMediaRec Order.setaudioencoder (MediaRecorder.AudioEncoder.AAC);//after Setoutputformat () Mmediarecorder.setvideoencoder (
MediaRecorder.VideoEncoder.H264);//after Setoutputformat ()//mmediarecorder.setvideoencodingbitrate (800);
Step 4:set Output File Mmediarecorder.setoutputfile (Result.mediapath); Step 5:set the preview output//Mmediarecorder.setorientaTionhint (90)//Add HTC Mobile phone will have problems LOG.E ("Yixia", "outputfile:" + Result.mediapath);
Mmediarecorder.prepare ();
Mmediarecorder.start ();
Mrecording = true;
return result;
catch (IllegalStateException e) {e.printstacktrace ();
LOG.E ("Yixia", "Startrecord", e);
catch (IOException e) {e.printstacktrace ();
LOG.E ("Yixia", "Startrecord", e);
catch (Exception e) {e.printstacktrace ();
LOG.E ("Yixia", "Startrecord", e);
} return null;
/** Stop recording/@Override public void Stoprecord () {Long endtime = System.currenttimemillis ();
if (Mmediarecorder!= null) {//set does not collapse after mmediarecorder.setonerrorlistener (null);
Mmediarecorder.setpreviewdisplay (NULL);
try {mmediarecorder.stop ();
catch (IllegalStateException e) {LOG.W ("Yixia", "Stoprecord", e); catch (RuntimeException e) {LOG.W ("Yixia", "Stoprecord"), e);
catch (Exception e) {LOG.W ("Yixia", "Stoprecord", e);
} if (camera!= null) {try {camera.lock ();
catch (RuntimeException e) {log.e ("Yixia", "Stoprecord", e);
} mrecording = false;
/** Release Resources */@Override public void releases () {super.release ();
if (Mmediarecorder!= null) {Mmediarecorder.setonerrorlistener (null);
try {mmediarecorder.release ();
catch (IllegalStateException e) {LOG.W ("Yixia", "Stoprecord", e);
catch (Exception e) {LOG.W ("Yixia", "Stoprecord", e);
} Mmediarecorder = null; @Override public void OnError (Mediarecorder mr, int what, int extra) {try {if (Mr!= null) MR.R
ESET ();
catch (IllegalStateException e) {LOG.W ("Yixia", "Stoprecord", e);
catch (Exception e) {LOG.W ("Yixia", "Stoprecord", e); } if (Monerrorlistener!= null) MonerroRlistener.onvideoerror (what, extra); }
Above is to the Android Mediarecorder data collation, follow-up continue to add, the need for friends can refer to.