How to create 30 second automated audio clip in Android using Java -


i'm working on side project fun casual use

in android studio i'm trying implement button click starts automatic 30 second audio recording user can or whatever in period of time.

after clip has finished auto plays , gives ability save or download directly device

i haven't started yet, more curious particular methods in api should looking into???

any advice amazing thank you.

try this:

private mediarecorder mmediarecorder; private static final long update_interval = 100; private sync msync; private boolean misrecording = false; private long mstarttime = 0; private long mstoptime = 0; private string mfilename;  private void startrecord() {     startrecording();     msync = new sync(new runnable() {          @override         public void run() {             if (!misrecording||!isadded())                 return;             long currenttime = system.currenttimemillis();             if (currenttime-mstarttime>appconstants.max_record_duration_s*1000){                 stoprecord();                 updatelayoutvisibility();                 return;                                              }             string str = getstring(r.string.recording_template,(currenttime-mstarttime)/1000,appconstants.max_record_duration_s);             mtextseconds.settext(str);             msync.next();         }     },update_interval);     msync.now();     mlayoutbuttonsstartrecord.setvisibility(view.gone);     mlayoutbuttonsrecord.setvisibility(view.visible); }   private void stoprecord() {     msync.stop();     misrecording = false;     mstoptime = system.currenttimemillis();     mmediarecorder.stop();     mmediarecorder.release();     mmediarecorder = null;       }  private void startrecording() {     if (mmediarecorder != null) {         mmediarecorder.release();     }     mfilename = gettemprecordfilename();     if (mfilename==null){         dismiss();         return;     }     misrecording = true;     mmediarecorder = new mediarecorder();     mmediarecorder.setaudiosource(audiosource.mic);     mmediarecorder.setoutputformat(outputformat.mpeg_4);     mmediarecorder.setaudioencoder(audioencoder.aac);     mmediarecorder.setaudiochannels(1);      mmediarecorder.setoutputfile(mfilename);     try {         mmediarecorder.prepare();         mmediarecorder.start();         mstarttime = system.currenttimemillis();     } catch (ioexception e) {         toast.maketext(getactivity(),                 r.string.error_failed_start_recording, toast.length_long)                 .show();         log.d(tag, "failed start recorder", e);         mmediarecorder.release();         mmediarecorder = null;         dismiss();         return;     } }  private class sync{     private handler handler = new handler();     private runnable task;     private long period;      public sync(runnable task,long period){         this.task = task;         this.period = period;         handler.removecallbacks(task);     }     public void now(){         task.run();     }      public void next(){         handler.postdelayed(task, period);     }     public void stop(){         handler.removecallbacks(task);     } }  @override public void onpause() {     super.onpause();      if (mmediarecorder != null) {         mmediarecorder.release();         mmediarecorder = null;     }     if (msync!=null){        msync.stop();     }  } 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -