6.7.0 - Alpha7 - 修复打包应用未勾选 MediaInfo/MLKit 库时应用崩溃的问题
This commit is contained in:
@@ -20,7 +20,6 @@ import com.hjq.toast.Toaster
|
|||||||
import com.tencent.bugly.Bugly
|
import com.tencent.bugly.Bugly
|
||||||
import com.tencent.bugly.crashreport.CrashReport
|
import com.tencent.bugly.crashreport.CrashReport
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||||
import org.autojs.autojs.apkbuilder.ApkBuilder
|
|
||||||
import org.autojs.autojs.app.GlobalAppContext
|
import org.autojs.autojs.app.GlobalAppContext
|
||||||
import org.autojs.autojs.core.pref.Pref
|
import org.autojs.autojs.core.pref.Pref
|
||||||
import org.autojs.autojs.core.ui.inflater.ImageLoader
|
import org.autojs.autojs.core.ui.inflater.ImageLoader
|
||||||
@@ -30,7 +29,6 @@ import org.autojs.autojs.external.receiver.DynamicBroadcastReceivers
|
|||||||
import org.autojs.autojs.ipc.InAppEventBus
|
import org.autojs.autojs.ipc.InAppEventBus
|
||||||
import org.autojs.autojs.leakcanary.LeakCanarySetup
|
import org.autojs.autojs.leakcanary.LeakCanarySetup
|
||||||
import org.autojs.autojs.pluginclient.DevPluginService
|
import org.autojs.autojs.pluginclient.DevPluginService
|
||||||
import org.autojs.autojs.runtime.api.augment.ocr.Ocr
|
|
||||||
import org.autojs.autojs.timing.TimedTaskManager
|
import org.autojs.autojs.timing.TimedTaskManager
|
||||||
import org.autojs.autojs.timing.TimedTaskScheduler
|
import org.autojs.autojs.timing.TimedTaskScheduler
|
||||||
import org.autojs.autojs.tool.CrashHandler
|
import org.autojs.autojs.tool.CrashHandler
|
||||||
@@ -172,7 +170,6 @@ class App : MultiDexApplication() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun initMlKitContext() {
|
private fun initMlKitContext() {
|
||||||
ApkBuilder.Libs.MLKIT_OCR.ensureLibFiles(Ocr.Companion.OcrMode.MLKIT.value)
|
|
||||||
MlKitContext.initializeIfNeeded(this)
|
MlKitContext.initializeIfNeeded(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,9 +17,10 @@ package org.mediainfo.android
|
|||||||
class MediaInfo {
|
class MediaInfo {
|
||||||
|
|
||||||
private var mIsCanceled: Int = 0
|
private var mIsCanceled: Int = 0
|
||||||
|
private var mIsAvailable = false
|
||||||
|
|
||||||
init {
|
init {
|
||||||
System.loadLibrary("mediainfo")
|
mIsAvailable = runCatching { System.loadLibrary("mediainfo") }.isSuccess
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -30,8 +31,8 @@ class MediaInfo {
|
|||||||
* @param parameter Parameter you are looking for in the stream (codec, width, bitrate, ...), in integer format
|
* @param parameter Parameter you are looking for in the stream (codec, width, bitrate, ...), in integer format
|
||||||
* @return a string about information you search, an empty string if there is a problem.
|
* @return a string about information you search, an empty string if there is a problem.
|
||||||
*/
|
*/
|
||||||
fun get(filename: String, streamKind: StreamKind, streamNum: Int, parameter: Int): String {
|
fun get(filename: String, streamKind: StreamKind, streamNum: Int, parameter: Int): String = checkAvailability {
|
||||||
return getById(filename, streamKind.ordinal, streamNum, parameter /* InfoKind.TEXT */)
|
getById(filename, streamKind.ordinal, streamNum, parameter /* InfoKind.TEXT */)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -43,8 +44,8 @@ class MediaInfo {
|
|||||||
* @param infoKind Kind of information you want about the parameter (the text, the measure, the help, ...)
|
* @param infoKind Kind of information you want about the parameter (the text, the measure, the help, ...)
|
||||||
* @return a string about information you search, an empty string if there is a problem.
|
* @return a string about information you search, an empty string if there is a problem.
|
||||||
*/
|
*/
|
||||||
fun get(filename: String, streamKind: StreamKind, streamNum: Int, parameter: Int, infoKind: InfoKind): String {
|
fun get(filename: String, streamKind: StreamKind, streamNum: Int, parameter: Int, infoKind: InfoKind): String = checkAvailability {
|
||||||
return getByIdDetail(filename, streamKind.ordinal, streamNum, parameter, infoKind.ordinal)
|
getByIdDetail(filename, streamKind.ordinal, streamNum, parameter, infoKind.ordinal)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -55,8 +56,8 @@ class MediaInfo {
|
|||||||
* @param parameter Parameter you are looking for in the stream (codec, width, bitrate, ...), in string format ("Codec", "Width", ...)
|
* @param parameter Parameter you are looking for in the stream (codec, width, bitrate, ...), in string format ("Codec", "Width", ...)
|
||||||
* @return a string about information you search, an empty string if there is a problem
|
* @return a string about information you search, an empty string if there is a problem
|
||||||
*/
|
*/
|
||||||
fun get(filename: String, streamKind: StreamKind, streamNum: Int, parameter: String): String {
|
fun get(filename: String, streamKind: StreamKind, streamNum: Int, parameter: String): String = checkAvailability {
|
||||||
return getByName(filename, streamKind.ordinal, streamNum, parameter /* InfoKind.TEXT, InfoKind.NAME */)
|
getByName(filename, streamKind.ordinal, streamNum, parameter /* InfoKind.TEXT, InfoKind.NAME */)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -68,8 +69,8 @@ class MediaInfo {
|
|||||||
* @param infoKind Kind of information you want about the parameter (the text, the measure, the help, ...)
|
* @param infoKind Kind of information you want about the parameter (the text, the measure, the help, ...)
|
||||||
* @return a string about information you search, an empty string if there is a problem.
|
* @return a string about information you search, an empty string if there is a problem.
|
||||||
*/
|
*/
|
||||||
fun get(filename: String, streamKind: StreamKind, streamNum: Int, parameter: String, infoKind: InfoKind): String {
|
fun get(filename: String, streamKind: StreamKind, streamNum: Int, parameter: String, infoKind: InfoKind): String = checkAvailability {
|
||||||
return getByNameDetail(filename, streamKind.ordinal, streamNum, parameter, infoKind.ordinal, InfoKind.NAME.ordinal)
|
getByNameDetail(filename, streamKind.ordinal, streamNum, parameter, infoKind.ordinal, InfoKind.NAME.ordinal)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -82,8 +83,8 @@ class MediaInfo {
|
|||||||
* @param searchKind Where to look for the parameter
|
* @param searchKind Where to look for the parameter
|
||||||
* @return a string about information you search, an empty string if there is a problem.
|
* @return a string about information you search, an empty string if there is a problem.
|
||||||
*/
|
*/
|
||||||
fun get(filename: String, streamKind: StreamKind, streamNum: Int, parameter: String, infoKind: InfoKind, searchKind: InfoKind): String {
|
fun get(filename: String, streamKind: StreamKind, streamNum: Int, parameter: String, infoKind: InfoKind, searchKind: InfoKind): String = checkAvailability {
|
||||||
return getByNameDetail(filename, streamKind.ordinal, streamNum, parameter, infoKind.ordinal, searchKind.ordinal)
|
getByNameDetail(filename, streamKind.ordinal, streamNum, parameter, infoKind.ordinal, searchKind.ordinal)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -92,8 +93,8 @@ class MediaInfo {
|
|||||||
* @param streamKind Kind of Stream (general, video, audio, ...)
|
* @param streamKind Kind of Stream (general, video, audio, ...)
|
||||||
* @return number of streams of the given stream kind
|
* @return number of streams of the given stream kind
|
||||||
*/
|
*/
|
||||||
fun countGet(filename: String, streamKind: StreamKind): Int {
|
fun countGet(filename: String, streamKind: StreamKind): Int = checkAvailability {
|
||||||
return countGet(filename, streamKind.ordinal, -1)
|
countGet(filename, streamKind.ordinal, -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -103,21 +104,19 @@ class MediaInfo {
|
|||||||
* @param streamNumber Stream number in Kind of stream
|
* @param streamNumber Stream number in Kind of stream
|
||||||
* @return number of streams of the given stream kind
|
* @return number of streams of the given stream kind
|
||||||
*/
|
*/
|
||||||
fun countGet(filename: String, streamKind: StreamKind, streamNumber: Int): Int {
|
fun countGet(filename: String, streamKind: StreamKind, streamNumber: Int): Int = checkAvailability {
|
||||||
return countGet(filename, streamKind.ordinal, streamNumber)
|
countGet(filename, streamKind.ordinal, streamNumber)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getMI(filename: String): String {
|
fun getMI(filename: String): String = checkAvailability {
|
||||||
return getMediaInfo(filename)
|
getMediaInfo(filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getMIOption(param: String): String {
|
fun getMIOption(param: String): String = checkAvailability {
|
||||||
return getMediaInfoOption(param)
|
getMediaInfoOption(param)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getIsCanceled() = mIsCanceled
|
fun getMediaInfoTrimmed(filename: String): String = checkAvailability {
|
||||||
|
|
||||||
fun getMediaInfoTrimmed(filename: String): String {
|
|
||||||
var result = getMediaInfo(filename)
|
var result = getMediaInfo(filename)
|
||||||
|
|
||||||
replaceMap.forEach { map ->
|
replaceMap.forEach { map ->
|
||||||
@@ -129,13 +128,17 @@ class MediaInfo {
|
|||||||
result.split("\n").forEach { s ->
|
result.split("\n").forEach { s ->
|
||||||
countSpacesBeforeColon(s).let { if (maxWhitespaceToTrim == 0 || it in 1..maxWhitespaceToTrim) maxWhitespaceToTrim = it }
|
countSpacesBeforeColon(s).let { if (maxWhitespaceToTrim == 0 || it in 1..maxWhitespaceToTrim) maxWhitespaceToTrim = it }
|
||||||
}
|
}
|
||||||
return result.split("\n")
|
result.split("\n")
|
||||||
.joinToString("\n") {
|
.joinToString("\n") {
|
||||||
trimSpacesBeforeColon(it, maxOf(0, maxWhitespaceToTrim - 1))
|
trimSpacesBeforeColon(it, maxOf(0, maxWhitespaceToTrim - 1))
|
||||||
.replace(Regex("^[A-Z][a-z]+$"), "# $0")
|
.replace(Regex("^[A-Z][a-z]+$"), "# $0")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun isCanceled() = mIsCanceled
|
||||||
|
|
||||||
|
fun isAvailable() = mIsAvailable
|
||||||
|
|
||||||
private fun countSpacesBeforeColon(input: String): Int {
|
private fun countSpacesBeforeColon(input: String): Int {
|
||||||
val index = input.indexOf(':')
|
val index = input.indexOf(':')
|
||||||
if (index == -1) return 0 // 如果没有冒号, 则返回0
|
if (index == -1) return 0 // 如果没有冒号, 则返回0
|
||||||
@@ -174,6 +177,11 @@ class MediaInfo {
|
|||||||
|
|
||||||
private external fun countGet(filename: String, streamKind: Int, streamNum: Int): Int
|
private external fun countGet(filename: String, streamKind: Int, streamNum: Int): Int
|
||||||
|
|
||||||
|
private fun <R> checkAvailability(func: () -> R): R {
|
||||||
|
require(mIsAvailable) { "MediaInfo library is not available" }
|
||||||
|
return func()
|
||||||
|
}
|
||||||
|
|
||||||
// @Remark
|
// @Remark
|
||||||
// ! Don't change it carelessly. This order is from MediaInfo_Const.h
|
// ! Don't change it carelessly. This order is from MediaInfo_Const.h
|
||||||
enum class StreamKind {
|
enum class StreamKind {
|
||||||
|
|||||||
Reference in New Issue
Block a user