Skip to content

Commit

Permalink
feat: 添加异常捕获
Browse files Browse the repository at this point in the history
  • Loading branch information
hexleo committed Dec 17, 2020
1 parent ea6fd49 commit a2ffcc4
Showing 1 changed file with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ object MediaUtil {

private const val TAG = "${Constant.TAG}.MediaUtil"

val isDeviceSupportHevc by lazy { checkCodec("video/hevc") }
val isDeviceSupportHevc by lazy {
checkCodec("video/hevc")
}

fun getExtractor(file: FileContainer): MediaExtractor {
val extractor = MediaExtractor()
Expand Down Expand Up @@ -73,19 +75,25 @@ object MediaUtil {
* 检查设备解码支持类型
*/
private fun checkCodec(mimeType: String): Boolean {
val numCodecs = MediaCodecList.getCodecCount()
for (i in 0 until numCodecs) {
val codecInfo = MediaCodecList.getCodecInfoAt(i)
if (!codecInfo.isEncoder) {
continue
}
val types = codecInfo.supportedTypes
for (j in types.indices) {
if (types[j].equals(mimeType, ignoreCase = true)) {
return true
try {
val numCodecs = MediaCodecList.getCodecCount()
for (i in 0 until numCodecs) {
val codecInfo = MediaCodecList.getCodecInfoAt(i)
if (!codecInfo.isEncoder) {
continue
}
val types = codecInfo.supportedTypes
for (j in types.indices) {
if (types[j].equals(mimeType, ignoreCase = true)) {
return true
}
}
}
return false
} catch (t: Throwable) {
ALog.e(TAG, "checkCodec $t")
return false
}
return false

}
}

0 comments on commit a2ffcc4

Please sign in to comment.