This commit is contained in:
Horis
2025-04-01 17:31:23 +08:00
parent 3ad189b9ef
commit 5654a2e56d
6 changed files with 21 additions and 12 deletions

View File

@@ -27,12 +27,7 @@ class InputStreamDataSource(private val supplier: () -> InputStream) : BaseDataS
inputStream.skip(dataSpec.position)
if (dataSpec.length == C.LENGTH_UNSET.toLong()) {
bytesRemaining = inputStream.available().toLong()
if (bytesRemaining == 0L) bytesRemaining = C.LENGTH_UNSET.toLong()
} else {
bytesRemaining = dataSpec.length
}
bytesRemaining = dataSpec.length
opened = true
transferStarted(dataSpec)

View File

@@ -550,6 +550,7 @@ class HttpReadAloudService : BaseReadAloudService(),
override fun onPlayerError(error: PlaybackException) {
super.onPlayerError(error)
AppLog.put("朗读错误\n${contentList[nowSpeak]}", error)
deleteCurrentSpeakFile()
playErrorNo++
if (playErrorNo >= 5) {
toastOnUi("朗读连续5次错误, 最后一次错误代码(${error.localizedMessage})")
@@ -558,7 +559,6 @@ class HttpReadAloudService : BaseReadAloudService(),
} else {
if (exoPlayer.hasNextMediaItem()) {
exoPlayer.seekToNextMediaItem()
exoPlayer.playWhenReady = true
exoPlayer.prepare()
} else {
exoPlayer.clearMediaItems()
@@ -567,6 +567,15 @@ class HttpReadAloudService : BaseReadAloudService(),
}
}
private fun deleteCurrentSpeakFile() {
if (AppConfig.streamReadAloudAudio) {
return
}
val mediaItem = exoPlayer.currentMediaItem ?: return
val filePath = mediaItem.localConfiguration!!.uri.path!!
File(filePath).delete()
}
override fun aloudServicePendingIntent(actionStr: String): PendingIntent? {
return servicePendingIntent<HttpReadAloudService>(actionStr)
}

View File

@@ -253,7 +253,6 @@ class ChangeBookSourceDialog() : BaseDialogFragment(R.layout.dialog_book_change_
delay(500)
}
}
}
lifecycleScope.launch {

View File

@@ -25,6 +25,7 @@ import io.legado.app.help.config.SourceConfig
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.model.webBook.WebBook
import io.legado.app.utils.internString
import io.legado.app.utils.mapParallel
import io.legado.app.utils.mapParallelSafe
import io.legado.app.utils.onEachIndexed
import io.legado.app.utils.toastOnUi
@@ -35,6 +36,7 @@ import kotlinx.coroutines.Job
import kotlinx.coroutines.asCoroutineDispatcher
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.currentCoroutineContext
import kotlinx.coroutines.ensureActive
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
@@ -231,11 +233,13 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a
}
}.onStart {
searchStateData.postValue(true)
}.mapParallelSafe(threadCount) {
runCatching {
}.mapParallel(threadCount) {
try {
withTimeout(60000L) {
search(it)
}
} catch (_: Throwable) {
currentCoroutineContext().ensureActive()
}
it
}.onEachIndexed { index, value ->

View File

@@ -64,7 +64,7 @@ inline fun <T, R> Flow<T>.mapParallelSafe(
flow {
try {
emit(transform(value))
} catch (e: Throwable) {
} catch (_: Throwable) {
coroutineContext.ensureActive()
}
}

View File

@@ -159,7 +159,9 @@ object UrlUtil {
.substringAfterLast(".", "")
//检查截取的后缀字符是否合法 [a-zA-Z0-9]
return if (suffix.length > 5 || !suffix.matches(fileSuffixRegex)) {
AppLog.put("Cannot find legal suffix:\n target: $str\n suffix: $suffix")
if (default == null) {
AppLog.put("Cannot find legal suffix:\n target: $str\n suffix: $suffix")
}
default ?: "ext"
} else {
suffix