java - Android MediaRecorder Crashes -


updated:

ok, after few days of testing , debugging... got work, not way want.

the reason crashed because of "reorientation" of camera during lockscreen, apparently, crashes often.

once forced use landscape mode, works. however, don't want use landscape mode; want work in portrait mode.

the code taken directly android studio's sample (media -> mediarecorder). sample had code working in landscape mode, , can't figure how use portrait mode can avoid re-orientation , avoid crashes?

there's nothing in onpause, onresume code , stacktrace pointed toward method being called.

easy reproduce:

1) use android studio mediarecord sample app 2) in manifest, change, android:screenorientation="landscape"> portrait. 3) app won't launch now.

i added mcamera.setdisplayorientation(90), same issue.

code:

@targetapi(build.version_codes.honeycomb) private boolean preparevideorecorder(){      // begin_include (configure_preview)     mcamera = camerahelper.getdefaultcamerainstance();      // need make sure our preview , recording video size supported     // camera. query camera find sizes , choose optimal size given     // dimensions of our preview surface.     camera.parameters parameters = mcamera.getparameters();     list<camera.size> msupportedpreviewsizes = parameters.getsupportedpreviewsizes();     camera.size optimalsize = camerahelper.getoptimalpreviewsize(msupportedpreviewsizes,             mpreview.getwidth(), mpreview.getheight());      // use same size recording profile.     camcorderprofile profile = camcorderprofile.get(camcorderprofile.quality_high);     profile.videoframewidth = optimalsize.width;     profile.videoframeheight = optimalsize.height;      // likewise camera object itself.     parameters.setpreviewsize(profile.videoframewidth, profile.videoframeheight);     mcamera.setparameters(parameters);     try {             // requires api level 11+, backward compatibility use {@link setpreviewdisplay}             // {@link surfaceview}             mcamera.setpreviewtexture(mpreview.getsurfacetexture());     } catch (ioexception e) {         log.e(tag, "surface texture unavailable or unsuitable" + e.getmessage());         return false;     }     // end_include (configure_preview)      // begin_include (configure_media_recorder)     mmediarecorder = new mediarecorder();      // step 1: unlock , set camera mediarecorder     mcamera.unlock();     mmediarecorder.setcamera(mcamera);      // step 2: set sources     mmediarecorder.setaudiosource(mediarecorder.audiosource.default);     mmediarecorder.setvideosource(mediarecorder.videosource.camera);      // step 3: set camcorderprofile (requires api level 8 or higher)     mmediarecorder.setprofile(profile);      // step 4: set output file     mmediarecorder.setoutputfile(camerahelper.getoutputmediafile(             camerahelper.media_type_video).tostring());      mmediarecorder.setorientationhint(90);     // end_include (configure_media_recorder)      mediascannerconnection.scanfile(this, new string[] { camerahelper.getoutputmediafile(             camerahelper.media_type_video).getpath() }, new string[] { "video/mp4" }, null);     // step 5: prepare configured mediarecorder     try {         mmediarecorder.prepare();     } catch (illegalstateexception e) {         log.d(tag, "illegalstateexception preparing mediarecorder: " + e.getmessage());         releasemediarecorder();         return false;     } catch (ioexception e) {         log.d(tag, "ioexception preparing mediarecorder: " + e.getmessage());         releasemediarecorder();         return false;     }     return true; } 

logs:

06-27 02:18:08.244  25734-25752/com.watchdawg.watchdawg e/mediarecorder﹕ start failed: -22 06-27 02:18:08.253  25734-25752/com.watchdawg.watchdawg e/androidruntime﹕ fatal exception: asynctask #1 process: com.watchdawg.watchdawg, pid: 25734 java.lang.runtimeexception: error occured while executing doinbackground() @ android.os.asynctask$3.done(asynctask.java:304) @ java.util.concurrent.futuretask.finishcompletion(futuretask.java:355) @ java.util.concurrent.futuretask.setexception(futuretask.java:222) @ java.util.concurrent.futuretask.run(futuretask.java:242) @ android.os.asynctask$serialexecutor$1.run(asynctask.java:231) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1112) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:587) @ java.lang.thread.run(thread.java:818) caused by: java.lang.runtimeexception: start failed. @ android.media.mediarecorder.start(native method) @ com.watchdawg.watchdawg.recordactivity$mediapreparetask.doinbackground(recordactivity.java:276) @ com.watchdawg.watchdawg.recordactivity$mediapreparetask.doinbackground(recordactivity.java:267) @ android.os.asynctask$2.call(asynctask.java:292) @ java.util.concurrent.futuretask.run(futuretask.java:237) @ android.os.asynctask$serialexecutor$1.run(asynctask.java:231) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1112) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:587) @ java.lang.thread.run(thread.java:818) 

whenever application removed recent task list, process not cleaned completely, ui cleaned up. app responsibility cleanup resource held activity or app. hence, need override ontaskremoved() method in service(android service) component , perform cleanup(releasing mediaplayer instance etc).


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -

jdbc - Not able to establish database connection in eclipse -