android - The application crashes when the media recorder starts? -
i using media recorder record calls in android. times mediarecorder recording audio , times doesn't record audio. when play recorded audio error shown "the player doesn't supports type of audio file ".
the below code recording audio
try { f1 = file.createtempfile("sound", ".mp3", dir); } catch (ioexception e) { e.printstacktrace(); } filename = f1.getname(); mediarecorder = new mediarecorder(); mediarecorder.setaudiosource(mediarecorder.audiosource.mic); mediarecorder.setoutputformat(mediarecorder.outputformat.mpeg_4); mediarecorder.setaudioencoder(mediarecorder.audioencoder.aac); mediarecorder.setoutputfile(f1.getabsolutepath()); try { mediarecorder.prepare(); } catch (illegalstateexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } mediarecorder.start(); recordstarted = true;
my logcat error shown below
e/mediarecorder: start failed: -38 07-03 11:10:23.718 8558-8558/com.seyali.calllog e/uncaughtexception: java.lang.runtimeexception: unable start receiver com.seyali.calllog.receiver.callreceiver: java.lang.illegalstateexception @ android.app.activitythread.handlereceiver(activitythread.java:2593) @ android.app.activitythread.access$1700(activitythread.java:139) @ android.app.activitythread$h.handlemessage(activitythread.java:1369) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:149) @ android.app.activitythread.main(activitythread.java:5257) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:515) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:609) @ dalvik.system.nativestart.main(native method) caused by: java.lang.illegalstateexception @ android.media.mediarecorder.start(native method) @ com.seyali.calllog.receiver.callreceiver.onreceive(callreceiver.java:175) @ android.app.activitythread.handlereceiver(activitythread.java:2586) @ android.app.activitythread.access$1700(activitythread.java:139) @ android.app.activitythread$h.handlemessage(activitythread.java:1369) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:149) @ android.app.activitythread.main(activitythread.java:5257) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:515) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:609) @ dalvik.system.nativestart.main(native method)
please me how solve this.
illegal state means media recorder not ready recording. there might several reasons it. first of all, make sure can reach file want play. if fine, checkout media recorder diagram state should play. https://developer.android.com/reference/android/media/mediarecorder.html
also, happens if mediarecorder.prepare()
? should put mediarecorder.start()
try block.
Comments
Post a Comment