今天記錄一個坑,使用MediaPlayer播放視頻時出現了黑屏的情況,然後看控制檯輸出的系統日誌中包含了一個“MediaPlayer error (1, -2147483648)”
然後我就去查了一下源碼,發現了這個
public interface OnErrorListener
{
/**
* Called to indicate an error.
*
* @param mp the MediaPlayer the error pertains to
* @param what the type of error that has occurred:
* <ul>
* <li>{@link #MEDIA_ERROR_UNKNOWN}
* <li>{@link #MEDIA_ERROR_SERVER_DIED}
* </ul>
* @param extra an extra code, specific to the error. Typically
* implementation dependent.
* <ul>
* <li>{@link #MEDIA_ERROR_IO}
* <li>{@link #MEDIA_ERROR_MALFORMED}
* <li>{@link #MEDIA_ERROR_UNSUPPORTED}
* <li>{@link #MEDIA_ERROR_TIMED_OUT}
* <li><code>MEDIA_ERROR_SYSTEM (-2147483648)</code> - low-level system error.
* </ul>
* @return True 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.
*/
boolean onError(MediaPlayer mp, int what, int extra);
}
那麼我所遇到的問題就是“MEDIA_ERROR_SYSTEM”這個錯誤,其原因是“系統版本過低錯誤”(瞎翻譯的)。。。然後我又在網上查了一波,發現是因爲視頻文件通常是mp4、avi等格式的,但是即便是同一種文件格式,它們的編碼格式也可能不一樣。比如常見的編碼格式有:H.264、H.263等。但許多Andorid設備都只能支持部分編碼方式,這也就導致了有些視頻沒法在Andorid設備上播放,如果非要對這些視頻進行播放,就涉及到了視頻轉碼的複雜的操作了。。。目前我還沒學會這種技能,也算挖個坑,以後慢慢填吧