android - Audio Recorder Error -


i trying make voice recorder .when clicking on record button gives error fatal exception: main process: rishabh.agarwal.holmes.recorder, pid: 22175 java.lang.illegalstateexception @ android.media.mediarecorder.setoutputformat(native method) @ rishabh.agarwal.holmes.recorder.mainactivity$2.onclick(mainactivity.java:47)

this code

public class mainactivity extends appcompatactivity {  button btnplay,btnrec,btnstop; mediarecorder mr; string fname; @override protected void oncreate(bundle savedinstancestate) {     // todo auto-generated method stub     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);     fname=environment.getexternalstoragedirectory()+"/myrec1.3gp";     btnplay=(button)findviewbyid(r.id.button1);     btnrec=(button)findviewbyid(r.id.button2);     btnstop=(button)findviewbyid(r.id.button3);     btnplay.setenabled(false);     btnstop.setenabled(false);     btnplay.setonclicklistener(new onclicklistener() {           @override         public void onclick(view v) {           }     });      btnrec.setonclicklistener(new onclicklistener() {          @override         public void onclick(view v) {             mr = new mediarecorder();             mr.setoutputfile(fname);             mr.setoutputformat(mediarecorder.outputformat.three_gpp);             mr.setaudioencoder(mediarecorder.outputformat.amr_nb);             mr.setaudiosource(mediarecorder.audiosource.mic);             try {                 mr.prepare();             } catch (illegalstateexception e) {                  e.printstacktrace();                // toast.maketext(mainactivity.this, e.tostring(), 5).show();             } catch (ioexception e) {                 // todo auto-generated catch block                // toast.maketext(mainactivity.this, e.tostring(), 5).show();                 e.printstacktrace();             }             mr.start();             btnrec.setenabled(false);             btnstop.setenabled(true);         }     });      btnstop.setonclicklistener(new onclicklistener() {          @override         public void onclick(view v) {             mr.release();             mr.stop();          }     }); } 

}

try removing line

mr.setoutputformat(mediarecorder.outputformat.three_gpp); 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -