java - Android call recorder application -
i have developed basic call recorder application, working fine on devices versions below 'lollipop', when have run lollipop devices (android 5.0) i'm getting error.
e/mediarecorder(29786): start failed: -2147483648 java.lang.runtimeexception: start failed. @ android.media.mediarecorder.start(native method) @ com.androiddoc.callrecorder_anirbanjana.callrecordingservice.startrec(callrecordingservice.java:234) @ com.androiddoc.callrecorder_anirbanjana.callrecordingservice.oncreate(callrecordingservice.java:54) @ android.app.activitythread.handlecreateservice(activitythread.java:2763) @ android.app.activitythread.access$1800(activitythread.java:148) @ android.app.activitythread$h.handlemessage(activitythread.java:1375) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:135) @ android.app.activitythread.main(activitythread.java:5312) @ java.lang.reflect.method.invoke(native method) @ java.lang.reflect.method.invoke(method.java:372) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:901) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:696)
my code below. when call recorder.prepare(); , recorder.start(); i'm getting above error , can't work out why. can advise?
public class callrecordingservice extends service { mediarecorder myrec = new mediarecorder(); boolean isrecmode = false; private static final int recorder_samplerate = 8000; private static final int recorder_channels = audioformat.channel_in_mono; private static final int recorder_audio_encoding = audioformat.encoding_pcm_16bit; private audiorecord recorder = null; private thread recordingthread = null; private boolean isrecording = false; int buffersize = audiorecord.getminbuffersize(recorder_samplerate, recorder_channels, recorder_audio_encoding); @override public ibinder onbind(intent arg0) { return null; } public int onstartcommand(intent intent, int flags, int startid) { return start_sticky_compatibility; } @override public void oncreate() { // start recording startrec(); system.out.println("buffer size value " + buffersize); super.oncreate(); } public void stoprec() { myrec.reset(); toast.maketext(callrecordingservice.this, "rec stoped", toast.length_short).show(); log.i("callrecordingservice", "rec stoped"); isrecmode = false; } public void startrec() { try { // string selectedpath = this.getapplicationcontext().getfilesdir() // + "/system_sound"; string selectedpath = environment.getexternalstoragedirectory() + "/testing"; simpledateformat sdf = new simpledateformat( "dd_mm_yyyy_hh_mm_ss aa"); string currentdateandtime = sdf.format(new date()); // crate folder if not exist // string packagename = this.getpackagename(); file yourdir = new file(environment.getexternalstoragedirectory() + "/testing"); // file yourdir = new // file(this.getapplicationcontext().getfilesdir() + // "/system_sound"); if (!yourdir.exists()) { yourdir.mkdirs(); } // string selectedpath = // environment.getexternalstoragedirectory().getabsolutepath() + // "/android/data/" + packagename + "/system_sound"; myrec.setaudiosource(mediarecorder.audiosource.voice_call); myrec.setoutputformat(mediarecorder.outputformat.three_gpp); myrec.setaudioencoder(mediarecorder.audioencoder.amr_nb); // myrec.setoutputfile(environment.getexternalstoragedirectory().getpath()+"/my_rec_voice.mp3"); myrec.setoutputfile(selectedpath + "/" + currentdateandtime + "_" + getfrompreference("phoneno") + ".amr"); audiomanager am; // audio manager = (audiomanager) getsystemservice(context.audio_service); am.setmode(audiomanager.mode_in_call); int volume_level = .getstreamvolume(audiomanager.stream_voice_call); int max_volume = .getstreammaxvolume(audiomanager.stream_voice_call); if (volume_level < max_volume) { am.setstreamvolume(audiomanager.stream_voice_call, max_volume, audiomanager.flag_show_ui); } } catch (illegalstateexception e) { // log.e("call recorder illegalstateexception: ", ""); terminateanderasefile(); } catch (exception e) { // log.e("call recorder exception: ", ""); terminateanderasefile(); } onerrorlistener errorlistener = new onerrorlistener() { public void onerror(mediarecorder arg0, int arg1, int arg2) { terminateanderasefile(); } }; myrec.setonerrorlistener(errorlistener); try { log.v("call recorder", "media recorder prepared"); myrec.prepare(); } catch (illegalstateexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } try { log.v("call recorder", "media recorder started "); myrec.start(); } catch (exception e) { e.printstacktrace(); } toast.maketext(callrecordingservice.this, "rec start", toast.length_short).show(); log.i("callrecordingservice", "rec start"); isrecmode = true; } @override public void ondestroy() { stoprec(); //stoprecording(); if (isrecmode) { // stop recording myrec.stop(); } myrec.release(); super.ondestroy(); } // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // preference variable // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // -------------------------------------------- // method save variable in preference // -------------------------------------------- public void saveinpreference(string name, string content) { sharedpreferences preferences = preferencemanager .getdefaultsharedpreferences(this); sharedpreferences.editor editor = preferences.edit(); editor.putstring(name, content); editor.commit(); } // -------------------------------------------- // getting content preferences // -------------------------------------------- public string getfrompreference(string variable_name) { string preference_return; sharedpreferences preferences = preferencemanager .getdefaultsharedpreferences(this); preference_return = preferences.getstring(variable_name, ""); return preference_return; } // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // preference variable // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ private void terminateanderasefile() { try { toast toast = toast.maketext(this, this.getstring(r.string.reciever_end_call), toast.length_short); toast.show(); } catch (illegalstateexception e) { e.printstacktrace(); } toast toast = toast.maketext(this, this.getstring(r.string.record_impossible), toast.length_long); toast.show(); } }
Comments
Post a Comment