본문 바로가기

Android/Samples & Tips

[Android] MediaRecorder error - Front Camera: start failed: -16


MediaRecorder와 Camera를 이용해 캡쳐화면을 레코딩할때, Nexus S에서 start failed: -16이라는 에러가 발생했습니다.

front camera(전면 카메라)를 사용할때, CamcorderProfile의 퀄리티를 High로 주고,
recorder를 start() 하면 해당 에러가 발생합니다.

 E/MediaRecorder(-): start failed: -16
 E/AndroidRuntime(-): FATAL EXCEPTION: main
 E/AndroidRuntime(-): java.lang.RuntimeException: start failed.
 E/AndroidRuntime(-): at android.media.MediaRecorder.start(Native Method)

에러 로그는 이런식으로 출력되더라구요.
구글링으로 이런 에러를 겪은 경우를 찾아보는데, Nexus S에서만 이런 문제가 굉장히 많이 있더라구요. 

이 문제는 Nexus S에서만 생기는 듯 하고, CamcorderProfile을 이용해 퀄리티를 High로 변경해서 MediaRecorder에 설정할때만 발생하는듯 합니다.
(CamcorderProfile.get(CamcorderProfile.QUALITY_LOW)로 테스트한 결과, 문제 없었습니다.)



레퍼런스에서 MediaRecorder.start() 메소드를 보았습니다.

 public void start()

 Begins capturing and encoding data to the file specified with setOutputFile(). Call this after prepare().

 Since API level 13,
 if applications set a camera via setCamera(Camera), the apps can use the camera after this method call.
 The apps do not need to lock the camera again.
 However, if this method fails, the apps should still lock the camera back.
 The apps should not start another recording session during recording.

Throws
IllegalStateExceptionif it is called before prepare().

"prepare()를 호출하지 않은 상황에서는 IllegalStateException이 난다"라고 되어있는데, IllegalStateException은 아니고...

setCamera(Camera) 메소드를 이용해서 카메라를 설정한 경우에는 start() 메소드를 호출한 이후에 사용이 가능하고, 다시 카메를 락 할 필요가 없고..

start() 메소드가 fail된 경우, 해당 애플리케이션의 카메라가 락되어있는 경우일거라고 하고....

해당 애플리케이션은 레코딩을 하는 동안에는 다른 레코딩 세션을 시작하지 않을거다....

......

start failed / -16 / MediaRecorder / Nexus S로 검색을 다시 했습니다.

stack overflow에서 보니, CamcorderProfile에서 제공해주는 속성으로 profile을 설정할 경우에는 문제가 없다고 하는데, 저는 문제가 생기는 군요.

넥서스 S에서만 이런 문제가 발생하니...

여기저기 기웃기웃 하다가, CamcorderProfile을 이용해 MediaRecorder에 profile을 set하는 코드들을 둘러보았습니다.

CamcorderProfile의 get 메소드는 overload 되어있더라구요.

Public Methods
static CamcorderProfile get(int quality)
Returns the camcorder profile for the first back-facing camera on the device at the given quality level.
static CamcorderProfile get(int cameraId, int quality)
Returns the camcorder profile for the given camera at the given quality level.

이 중 cameraId를 지정하는 메소드가 있어서 이 메소드를 이용해 프로필을 설정해보았습니다.

CamcorderProfile.QUALITY_HIGH만 파라미터로 넘기던 내용을 cameraId까지 함께 지정해주니, Nexus S 에서 잘 동작하더라구요. 물론 다른 기기들에서도 기존처럼 정상 동작합니다.



저의 경우에는 만들고 있는 어플들이나 만들었던 어플 중에서 미디어레코더를 이용할 일이 없었기때문에 이런 경험을 하지 못했었는데, 이런 경우가 있어서 정리해둡니다.