0

我已经创建了录音机。旋转我的设备时,音频将自动保存。我怎样才能避免这种情况?我在设备上使用 Android 4.1.1。

   private MediaRecorder mRecorder = null;
     private static final String LOG_TAG = "MediaAudioCapture";
     ImageButton button_audio_button = (ImageButton) findViewById(R.id.audio_button);
      button_audio_button.setOnClickListener(new OnClickListener() {
      public void onClick(View record_button) {
      ImageButton audio_button = (ImageButton) record_button;
      if (!started_note_recording) {
        if (!started_recording) {
          startRecording();
          audio_button.setImageResource(R.drawable.audio_red);
         } else {
         stopRecording();
         audio_button.setImageResource(R.drawable.audio);
         }
        }
      }
     });
    private void startRecording() {
    mRecorder = new MediaRecorder();
    mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    mRecorder.setOutputFile(output.getAbsolutePath());
    mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
    ImageButton button_audio_button = (ImageButton)findViewById(R.id.audio_button);
    button_audio_button.setImageResource(R.drawable.audio);
    }
   }
  });
    try {
      mRecorder.prepare();
     } catch (IOException e) {
   Log.e(LOG_TAG, "prepare() failed");
   }
  mRecorder.start();
  stopWatch.start();
   }
4

1 回答 1

0

那是因为当你旋转时,活动将被重新加载。您可以将方向固定为纵向,或者您必须更改逻辑以保留旋转状态。

于 2013-05-17T12:03:16.827 回答