마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

안드로이드 MediaPlayer onError 코드 질문입니다

0 추천
안녕하세요. MediaPlayer로 HLS 스트리밍을 구현하는데요

MediaPlayer 에러코드가 1로 떨어지면 UNKNOWN 이라는데..

일반적으로 어떤 경우에 1로 떨어질 수 있나요?

그리고.. onError의 extra가 -1 또는 0은 어떤 코드인지 알 수 있을까요
Sinn 님이 2016년 11월 22일 질문

1개의 답변

0 추천
 
채택된 답변
public static final int MEDIA_ERROR_IO = -1004;
public static final int MEDIA_ERROR_MALFORMED = -1007;
public static final int MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK = 200;
public static final int MEDIA_ERROR_SERVER_DIED = 100;
public static final int MEDIA_ERROR_TIMED_OUT = -110;
public static final int MEDIA_ERROR_UNKNOWN = 1;
public static final int MEDIA_ERROR_UNSUPPORTED = -1010;

MediaPlayer 클래스 안에 상수로 위와 같이 정의 되어 있네요.

말씀하신 1은 UNKNOWN으로 정의 되어 있긴 한데

-1이랑 0은 없는데요.

혹시 몰라서 레퍼런스 사이트(https://developer.android.com/reference/android/media/MediaPlayer.OnErrorListener.html)도 긁어 놓겠습니다. 위의 코드값이랑 아래 extra 설명 참조해서 살펴보세요.

 

Public methods


onError

Added in API level 1

boolean onError (MediaPlayer mp, 
                int what, 
                int extra)

Called to indicate an error.

Parameters
mpMediaPlayer: the MediaPlayer the error pertains to
whatint: the type of error that has occurred:
extraint: an extra code, specific to the error. Typically implementation dependent.
Returns
booleanTrue if the method handled the error, false if it didn't. Returning false, or not having an OnErrorListener at all, will cause the OnCompletionListener to be called.
Development Guy (70,570 포인트) 님이 2016년 11월 23일 답변
답변 감사합니다.. 근데 진짜 extra code -1, 0 은 없는가보네요..
안드로이드 코드를 분석해 보세요.
0은 OK를 의미하는데, 0이 나왔다면 EOS(End Of Stream) 되었을 가능성이 높을 듯 합니다. -1의 경우 데이터를 못 읽은 것으로 생각됩니다.

제조사에서 안드로이드 소스를 수정했다면 다르겠지만 보통 HLS의 경우 NuPlayer.cpp를 사용합니다.
https://android.googlesource.com/platform/frameworks/av/+/437ced8a14944bf5450df50c5e7e7a6dfe20ea40/media/libmediaplayerservice/nuplayer/NuPlayer.cpp

코드를 보시면 notifyListener(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, err);  혹은       notifyListener(
                            MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, finalResult);
호출하는 부분이 있는데, 이게 에러를 반환하는 부분입니다.

이에 대한 사항은  
https://android.googlesource.com/platform/frameworks/av/+/master/media/libstagefright/mpeg2ts
https://android.googlesource.com/platform/frameworks/av/+/master/media/libstagefright/httplive 를 참조하세요.
...