outputstream - Android Java Save Audiorecord / Audiotrack to a file -


i have short code streams recorded audio in realtime speakers if user push start button. after pushes stop button, buffered audio should saved in mp3 file. file created empty. if try play file cant hear anything.

public class mainactivity extends activity {     boolean m_stop = true;     audiotrack m_audiotrack;     thread m_noisethread;     static final int buffersize = 200000;     audiorecord arec;     fileoutputstream os = null;      @override     protected void oncreate(bundle savedinstancestate)     {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);     }     public void onstartstopclicked(view v)     {         button startbutton = (button)findviewbyid(r.id.startstop);         if(m_stop) {             start();          } else {             stop();         }        }     runnable m_noisegenerator = new runnable()     {                public void run()         {             string filepath = environment.getexternalstoragedirectory().tostring();             os = new fileoutputstream(filepath + "/test.mp3");              int buffersize1 = audiorecord.getminbuffersize(11025, audioformat.channel_configuration_mono, audioformat.encoding_pcm_16bit);             arec = new audiorecord(mediarecorder.audiosource.mic, 11025, audioformat.channel_configuration_mono, audioformat.encoding_pcm_16bit, buffersize1);             m_audiotrack = new audiotrack(audiomanager.stream_music, 11025, audioformat.channel_out_mono, audioformat.encoding_pcm_16bit, 8000, audiotrack.mode_stream);              byte[] buffer = new byte[buffersize1];             arec.startrecording();             m_audiotrack.play();             while(!m_stop)             {                 arec.read(buffer, 0, buffersize1);                 m_audiotrack.write(buffer, 0, buffer.length);                     os.write(buffer);                         }         }     };     public void start()     {         m_stop = false;         m_noisethread = new thread(m_noisegenerator);         m_noisethread.start();     }     public void stop()     {         m_stop = true;             arec.stop();                 m_audiotrack.stop();         os.flush();         os.close();     }    } 

can me fix that? great :)


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -