Update HttpReadAloudService.kt
This commit is contained in:
@@ -29,9 +29,10 @@ import io.legado.app.R
|
||||
import io.legado.app.constant.AppLog
|
||||
import io.legado.app.constant.AppPattern
|
||||
import io.legado.app.data.appDb
|
||||
// 修复点1:补全 BookChapter 的引用,解决 unresolved reference title
|
||||
import io.legado.app.data.entities.BookChapter
|
||||
import io.legado.app.data.entities.HttpTTS
|
||||
import io.legado.app.exception.NoStackTraceException
|
||||
// 修正点1:修改 BookHelp 的引用路径
|
||||
import io.legado.app.help.book.BookHelp
|
||||
import io.legado.app.help.config.AppConfig
|
||||
import io.legado.app.help.coroutine.Coroutine
|
||||
@@ -68,7 +69,7 @@ import kotlin.coroutines.coroutineContext
|
||||
|
||||
/**
|
||||
* 在线朗读
|
||||
* (已修正:BookHelp 路径错误 & ReadBook 调用错误)
|
||||
* (最终修复版:修复了 index 命名错误和 import 缺失)
|
||||
*/
|
||||
@SuppressLint("UnsafeOptInUsageError")
|
||||
class HttpReadAloudService : BaseReadAloudService(),
|
||||
@@ -199,8 +200,8 @@ class HttpReadAloudService : BaseReadAloudService(),
|
||||
private suspend fun preDownloadAudios(httpTts: HttpTTS) {
|
||||
val book = ReadBook.book ?: return
|
||||
|
||||
// 修正点2:不再使用 ReadBook.textChapter,而是直接使用 Service 类中的 textChapter 属性
|
||||
val currentIdx = this.textChapter?.chapterIndex ?: return
|
||||
// 修复点2:将 chapterIndex 改为 index
|
||||
val currentIdx = this.textChapter?.index ?: return
|
||||
val limit = AppConfig.audioPreDownloadNum
|
||||
|
||||
for (i in 1..limit) {
|
||||
@@ -209,7 +210,6 @@ class HttpReadAloudService : BaseReadAloudService(),
|
||||
val targetIndex = currentIdx + i
|
||||
val chapter = appDb.bookChapterDao.getChapter(book.bookUrl, targetIndex) ?: break
|
||||
|
||||
// 修正点3:BookHelp 已在头部正确 Import,这里应该可以正常调用
|
||||
val contentString = BookHelp.getContent(book, chapter)
|
||||
|
||||
if (contentString.isNullOrEmpty()) continue
|
||||
@@ -284,8 +284,8 @@ class HttpReadAloudService : BaseReadAloudService(),
|
||||
downloaderChannel: Channel<Downloader>
|
||||
) {
|
||||
val book = ReadBook.book ?: return
|
||||
// 修正点4:同上,使用 this.textChapter
|
||||
val currentIdx = this.textChapter?.chapterIndex ?: return
|
||||
// 修复点3:将 chapterIndex 改为 index
|
||||
val currentIdx = this.textChapter?.index ?: return
|
||||
val limit = AppConfig.audioPreDownloadNum
|
||||
|
||||
for (i in 1..limit) {
|
||||
@@ -464,10 +464,9 @@ class HttpReadAloudService : BaseReadAloudService(),
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除缓存文件 (修正:使用 AppConfig.audioCacheCleanTime)
|
||||
* 移除缓存文件 (支持自定义清理时间)
|
||||
*/
|
||||
private fun removeCacheFile() {
|
||||
// 修正点5:同上,使用 this.textChapter
|
||||
val titleMd5 = MD5Utils.md5Encode16(this.textChapter?.title ?: "")
|
||||
FileUtils.listDirsAndFiles(ttsFolderPath)?.forEach {
|
||||
val isSilentSound = it.length() == 2160L
|
||||
|
||||
Reference in New Issue
Block a user