Android: MediaRecorder start failed : -16 -


i've been trying implement video camera. never worked because of mysterious error (-16) on recorder.start().

here code:

private void initrecorder(int width, int height) {         recorder.setaudiosource(mediarecorder.audiosource.camcorder);         recorder.setvideosource(mediarecorder.videosource.camera);          parameters params = camera.getparameters();         list<size> sizes = params.getsupportedpreviewsizes();         size optimalsize = getoptimalpreviewsize(sizes, width, height);         params.setpreviewsize(optimalsize.width, optimalsize.height);          camcorderprofile cphigh = camcorderprofile                 .get(camcorderprofile.quality_low);         recorder.setprofile(cphigh);         file mediafile = null;         if (environment.getexternalstoragestate().equals(                 environment.media_mounted)) {              mediafile = new file(                     android.os.environment.getexternalstoragedirectory()                             + "/towncare/temp/vid_temp.3gpp");             if (!mediafile.exists()) {                 try {                     mediafile.getparentfile().mkdirs();                     mediafile.createnewfile();                 } catch (ioexception e) {                     // todo auto-generated catch block                     e.printstacktrace();                 }             }         }         ;         recorder.setoutputfile(android.os.environment                 .getexternalstoragedirectory() + "/towncare/temp/vid_temp.3gpp");         recorder.setmaxduration(50000); // 50 seconds         recorder.setmaxfilesize(5000000);     }      private size getoptimalpreviewsize(list<size> sizes, int w, int h) {         final double aspect_tolerance = 0.1;         double targetratio = (double) w / h;         if (sizes == null)             return null;          size optimalsize = null;         double mindiff = double.max_value;          int targetheight = h;          // try find size match aspect ratio , size         (size size : sizes) {             double ratio = (double) size.width / size.height;             if (math.abs(ratio - targetratio) > aspect_tolerance)                 continue;             if (math.abs(size.height - targetheight) < mindiff) {                 optimalsize = size;                 mindiff = math.abs(size.height - targetheight);             }         }          // cannot find 1 match aspect ratio, ignore requirement         if (optimalsize == null) {             mindiff = double.max_value;             (size size : sizes) {                 if (math.abs(size.height - targetheight) < mindiff) {                     optimalsize = size;                     mindiff = math.abs(size.height - targetheight);                 }             }         }         return optimalsize;     }      private void preparerecorder() {         recorder.setpreviewdisplay(previewholder.getsurface());          try {             recorder.prepare();         } catch (illegalstateexception e) {             e.printstacktrace();             finish();         } catch (ioexception e) {             e.printstacktrace();             finish();         }     } 

here log:

04-20 18:27:26.178: i/mediarecorderjni(13225): prepare: surface=0x257468 (identity=1459) 04-20 18:27:27.548: e/mediarecorder(13225): start failed: -16 04-20 18:27:27.558: d/androidruntime(13225): shutting down vm 04-20 18:27:27.558: w/dalvikvm(13225): threadid=1: thread exiting uncaught exception (group=0x40018560) 04-20 18:27:27.578: e/androidruntime(13225): fatal exception: main 04-20 18:27:27.578: e/androidruntime(13225): java.lang.runtimeexception: start failed. 04-20 18:27:27.578: e/androidruntime(13225): @ android.media.mediarecorder.start(native method) 04-20 18:27:27.578: e/androidruntime(13225): @ com.packagename.app.fullcameraactivity$3.onclick(fullcameraactivity.java:84) 04-20 18:27:27.578: e/androidruntime(13225): @ android.view.view.performclick(view.java:2506) 04-20 18:27:27.578: e/androidruntime(13225): @ android.view.view$performclick.run(view.java:9116) 04-20 18:27:27.578: e/androidruntime(13225): @ android.os.handler.handlecallback(handler.java:587) 04-20 18:27:27.578: e/androidruntime(13225): @ android.os.handler.dispatchmessage(handler.java:92) 04-20 18:27:27.578: e/androidruntime(13225): @ android.os.looper.loop(looper.java:130) 04-20 18:27:27.578: e/androidruntime(13225): @ android.app.activitythread.main(activitythread.java:3835) 04-20 18:27:27.578: e/androidruntime(13225): @ java.lang.reflect.method.invokenative(native method) 04-20 18:27:27.578: e/androidruntime(13225): @ java.lang.reflect.method.invoke(method.java:507) 04-20 18:27:27.578: e/androidruntime(13225): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:864) 04-20 18:27:27.578: e/androidruntime(13225): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:622) 04-20 18:27:27.578: e/androidruntime(13225): @ dalvik.system.nativestart.main(native method)

i know there duplicates none of them has answers worked me. please me out here. in advance


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -