开发者

Record audio of one minute

I am working with audio recording in Android.

I want to record audio maximum of 1 minute and if user ask to stop before one minute it should be stop.

I have record audio code and it works perfectly.

How can I set time duration it?

If solution is thread.sleep then it's ok. I do something like same:

   if (start) {
       startRecording();
       try {
                Thread.sleep(60000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
  } else {
    //What should do ? to stop thread this Thread.sleep(60000);

  callToStopRecording();
  }

     private void startRecording() {
        mRecorder = new MediaRecorder();
        mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        mRecorder.setOutputFile(path + mFileName);
        mRecorder.setAudioEncoder(MediaRecorder开发者_JAVA技巧.AudioEncoder.AMR_NB);

        try {
            mRecorder.prepare();
        } catch (IOException e) {
            Log.e("Camera Error", "prepare() failed");
        }
        mRecorder.start();
    }

    private void stopRecording() {
        mRecorder.stop();
        mRecorder.release();
        mRecorder = null;
    }

but at stop recoding button, what do I need to write?


You can use this solution:

mRecorder.setMaxDuration(max_duration_ms);

The duation is in ms, so you have to use:

mRecorder.setMaxDuration(6000);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜