android - Media Recorder Start Failed-22 inside a thread -


hi trying make video recorder android app> reason need audio, have tried libraries nothing extracted me audio. approach instead of using native libraries can record video , audio separately? main thread records video , thread records audio. getting error when call start() method of media recorder class inside thread , start failed -22. following code.

public class mainactivity extends activity {   private surfaceholder surfaceholder;     private surfaceview surfaceview;     public mediarecorder mrec ;     imageview recordingbt;     public mediarecorder mrec2 = new mediarecorder();     file video;     private camera mcamera;     file audiofile = null;      file audiofile2 = null;     boolean recording=false;     textview tv;     view myview;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);     recordingbt= (imageview) findviewbyid(r.id.camera);     surfaceview = (surfaceview) findviewbyid(r.id.surface_camera);     tv=(textview) findviewbyid(r.id.textview1);       myview = findviewbyid(r.id.mybigview); }  @override protected void onstart(){     super.onstart();     log.i("recording activity", "we inside start function of recording activity");        log.i("recording activity", "opening camera");        mcamera = camera.open();       log.i("recording activity", "camera opened");         surfaceholder = surfaceview.getholder();         surfaceholder.settype(surfaceholder.surface_type_push_buffers);         recordingbt.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view v) {                  if(recording==false){                     try {                         log.i("recording activity", "recording start");                         startrecording();                     } catch (ioexception e) {                         // todo auto-generated catch block                         e.printstacktrace();                     }                 }                 else{                     stoprecording();                  }              }         });} public void startrecording() throws ioexception      {          recording=true;         string path= environment.getexternalstoragedirectory().tostring();         file sampledir = new file(path+"/dcim/squlium booth");         sampledir.mkdir();            log.i("setting path", sampledir.tostring());              try {               audiofile = file.createtempfile("sqb", ".3gp", sampledir);             } catch (ioexception e) {                return;}             log.i("recording activity", "seting media recorder attributes");            mrec = new mediarecorder();  // works          mcamera.unlock();         mrec.setcamera(mcamera);     mrec.setpreviewdisplay(surfaceholder.getsurface());      mrec.setvideosource(mediarecorder.videosource.camera);          mrec.setaudiosource(mediarecorder.audiosource.mic);          mrec.setmaxduration(60000);         mrec.setprofile(camcorderprofile.get(camcorderprofile.quality_high));         mrec.setoutputfile(audiofile.getabsolutepath());          mrec.prepare();         mrec.start();         startprogress(myview);       }   protected void stoprecording() {      recording=false;         mrec.stop();         mrec.release();         mcamera.lock();         mcamera.release();         mrec2.stop();         mrec.release();      }  public void startprogress(view view) {         // long         runnable runnable = new runnable() {            @override           public void run() {                  string path= environment.getexternalstoragedirectory().tostring();                 file sampledir = new file(path+"/dcim/squlium booth");                 sampledir.mkdir();                 try {                       audiofile2 = file.createtempfile("myaudio", ".mp3", sampledir);                     } catch (ioexception e) {                        return;}                  int minbuffersize = audiorecord.getminbuffersize(8000,                           audioformat .channel_in_mono,                           audioformat.encoding_pcm_16bit);                  mrec2.setaudiosource(mediarecorder.audiosource.mic);                  mrec2.setaudiosamplingrate(16000);                 mrec2.setoutputformat(mediarecorder.outputformat.amr_nb);                 mrec2.setaudioencoder(mediarecorder.audioencoder.amr_nb);                 mrec2.setoutputfile(audiofile2.getabsolutepath());                  try {                     mrec2.prepare();                 } catch (illegalstateexception e1) {                     log.i("illegal", "exception");                     e1.printstacktrace();                 } catch (ioexception e1) {                     log.i("iinput output", "exception");                 }                 log.i("inside run method", "starting thread there issue");                 mrec2.start();                 log.i("inside run method", "after start method inside thread");               log.i("inside thread", "alive");              }          };         new thread(runnable).start();   } 


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -