录制一分钟的音频

时间:2011-05-14 05:38:47

标签: android audio-recording

我正在Android中使用录音。

我想录制最长1分钟的音频,如果用户要求在一分钟之前停止播放,则应停止播放。

我有录制音频代码,效果很好。

如何设置持续时间呢?

如果解决方案是thread.sleep,那就没关系。我做了类似的事情:

   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.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;
    }

但是在停止重新编码按钮时,我需要写什么?

1 个答案:

答案 0 :(得分:3)

您可以使用此解决方案:

mRecorder.setMaxDuration(max_duration_ms);

持续时间以毫秒为单位,因此您必须使用:

mRecorder.setMaxDuration(6000);
相关问题