Android.media.MediaRecorder
Recoding step
기본 캠코더 레코딩 단계
- Unlock the camera with Camera.unlock().
- Configure MediaRecorder as shown in the code example above.
- Start recording using MediaRecorder.start().
- Record the video.
- Stop recording using MediaRecorder.stop().
- Release the media recorder with MediaRecorder.release().
- Lock the camera using Camera.lock().
|
List of methods
-
setAudioSource()
- 소리를 어디서부터 받아올지 설정한다. 마이크를 녹음하거나 통화 중 목소리 녹음, 통화 중 발신자 목소리만 녹음, 통화 중 수신자 목소리만 녹음 등을 결정한다.
-
setOutputFormat()
- 녹음 파일의 데이터 형식(format)을 설정한다.
-
setAudioEncoder()
- 인코더(코덱)을 설정한다.
-
setOutputFile()
- 녹음 파일의 경로 및 이름을 설정한다.
Example
샘플 녹음 예제:
private static void record() {
if (recorder != null) {
recorder.stop();
recorder.release();
recorder = null;
}
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
recorder.setOutputFile(filePath);
try {
recorder.prepare();
recorder.start();
Log.i(TAG, "recording start");
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
안드로이드 MediaRecorder 시스템 아키텍처
|
Troubleshooting
Start failed -16
MediaRecorder와 Camera를 이용해 캡쳐화면을 레코딩할때, Nexus S에서 start failed: -16이라는 에러가 발생할 수 있다.
Front camera(전면 카메라)를 사용할때, android.media.CamcorderProfile의 퀄리티를 High로 주고, Recorder를 start()
하면 해당 에러가 발생한다.
Stop failed -1007
- Stackoverflow: MediaRecorder.stop() stop failed: -1007
- [http://developer.android.com/reference/android/media/MediaRecorder.html#stop() Developer.android.com: MediaRecorder.stop() method]
아래와 같은 에러가 발생할 수 있다.
E/MediaRecorder(15709): stop failed: -1007
java.lang.RuntimeException: stop failed.
at android.media.MediaRecorder.stop(Native Method)
...
- that a RuntimeException is intentionally thrown to the application, if no valid audio/video data has been received when stop() is called.
- This happens if stop() is called immediately after start().
- Solved it at last. The issue was setting the preview size before setting the actual preview for the camera. The preview size MUST be equal to the selected video size.
See also
- android.media.MediaRecorder.AudioSource
- android.media.CamcorderProfile
- android.widget.VideoView
Favorite site
- Android developer MediaRecorder
- Develop > API Guides > Media and Camera > Audio Capture
- 안드로이드 동영상 녹화 분석
- Android 간단한 녹음 예제(Audio Recorder)
- 안드로이드 녹음 및 재생하기