开发者

Audio Recording and Out of memory Exception

hi i have audio recording in my i use mediarecorder class for recding audio but i have out of memory exception when i reach 2 m , that my limit. i given my code below.

time

private static void audiorecding() { if (audio_recding_stop_flag == 0) { audio_recding_stop_flag = 1;

        recorder.stop();
        recorder.reset();
        recorder.release();
        recorder=new MediaRecorder();
        int maxtime = audio_seekbar_play_indication.getMax();
        audio_seekbar_progress = 0;
        audio_seekbar_incr = maxtime/ AngiesData.gettotalaudiorecdingtimeinseconds(audio_recding_time.getText().toString());
        audio_recding_time.stop();
        recd_stop_audio.setBackgroundResource(R.drawable.rec_btn);
        audio_play_pause.setEnabled(true);
        delete_recding.setEnabled(true);

       AngiesData.angiesListContext.setAudioRecd(true);
       AngiesData.angiesListContext.setAudioRecdingTime((String) audio_recding_time.getText());
    } 
    else {


        audio_recding_stop_flag = 0;


        try {

            audio_play_pause.setEnabled(false);
            delete_recding.setEna开发者_高级运维bled(false);
            recd_stop_audio.setBackgroundResource(R.drawable.recording_stop);
            audio_recding_time .setBase(SystemClock.elapsedRealtime());
            audio_recding_time.start(); 
            recorder = new MediaRecorder();
            recorder.setAudioSource(MediaRecorder.AudioSource.MIC); // AudioSource
            recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT); // OutputFormat
            recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
            path = InitialValueLoader.sanitizePath("Audio/VoiceReport");
            InitialValueLoader.filecheck(path);
            recorder.setOutputFile(path);
            recorder.setMaxDuration(120000);
            recorder.prepare();
            recorder.start();


        } catch (Exception e) {
            e.printStackTrace();
        }   
}


I would try something with the AudioRecord-Class ( http://developer.android.com/reference/android/media/AudioRecord.html), use the read()-function with a while-loop and keep going until you got your 2 min. of samples (check the sampleRate, e.g. 44.1 Khz => 44100 smpls/sec => 60*44100 smpl/min). Making sure you have 2 min. of audio with the help of a timer is not a good idea. With timers you can never be sure on the precision, if another thread is interferring your timer will be evoked later, and in audio samples speaking it might be MUCH later.


I suggest useing a Chronometer instead of a timer


In programming if you have to deal with timings generally all time values are in milliseconds. You are trying to stop the recording after two seconds there not two minutes which would be 120000 milliseconds.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜