先看下mediaplayer.h對error類型的定義:
// Generic error codes for the media player framework. Errors are fatal, the// playback must abort.//// Errors are communicated back to the client using the// MediaPlayerListener::notify method defined below.// In this situation, 'notify' is invoked with the following:// 'msg' is set to MEDIA_ERROR.// 'ext1' should be a value from the enum media_error_type.// 'ext2' contains an implementation dependant error code to provide// more details. Should default to 0 when not used.//// The codes are distributed as follow:// 0xx: Reserved// 1xx: Android Player errors. Something went wrong inside the MediaPlayer.// 2xx: Media errors (e.g Codec not supported). There is a problem with the// media itself.// 3xx: Runtime errors. Some extraordinary condition arose making the playback// impossible.//enum media_error_type { // 0xx MEDIA_ERROR_UNKNOWN = 1, // 1xx MEDIA_ERROR_SERVER_DIED = 100, // 2xx MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK = 200, // 3xx};
常見錯誤類型
1. -2147483648 未知錯誤
例如log輸出:
MediaPlayer: error (1, -2147483648)
error的第一個參數1表示未知錯誤。
錯誤碼-2147483648是十進位表示的,對應16進位的0x80000000。
它定義在檔案:/frameworks/native/include/utils/Errors.h
UNKNOWN_ERROR = 0x80000000,
此錯誤一般是在framework的libmediaplayerservice,libstagefright目錄中拋出的。
在執行某個動作時被取消或者中斷,就會拋出此錯誤。
也是一個通用錯誤,在不知道錯誤原因時,也可以拋出此錯誤。
2. -107 網路連結錯誤
例如log輸出:
MediaPlayer: error (1, -107)