diff --git a/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt b/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt index 0c66e9181..df886f537 100644 --- a/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt +++ b/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt @@ -4,6 +4,7 @@ import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import android.view.KeyEvent +import io.legado.app.constant.AppLog import io.legado.app.constant.EventBus import io.legado.app.data.appDb import io.legado.app.help.AppConfig @@ -41,6 +42,7 @@ class MediaButtonReceiver : BroadcastReceiver() { val keycode: Int = keyEvent.keyCode val action: Int = keyEvent.action if (action == KeyEvent.ACTION_DOWN) { + AppLog.addLog("mediaButton $action") when (keycode) { KeyEvent.KEYCODE_MEDIA_PREVIOUS -> { if (context.getPrefBoolean("mediaButtonPerNext", false)) { @@ -86,6 +88,7 @@ class MediaButtonReceiver : BroadcastReceiver() { LifecycleHelp.isExistActivity(AudioPlayActivity::class.java) -> postEvent(EventBus.MEDIA_BUTTON, true) else -> if (AppConfig.mediaButtonOnExit || LifecycleHelp.activitySize() > 0 || !isMediaKey) { + AppLog.addLog("readAloud start Service") if (ReadBook.book != null) { ReadBook.readAloud() } else { diff --git a/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt b/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt index cc80c239c..d997840b8 100644 --- a/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt @@ -81,9 +81,9 @@ abstract class BaseReadAloudService : BaseService(), intent?.action?.let { action -> when (action) { IntentAction.play -> { + textChapter = ReadBook.curTextChapter pageIndex = ReadBook.durPageIndex() newReadAloud( - ReadBook.curTextChapter, intent.getBooleanExtra("play", true) ) } @@ -101,8 +101,8 @@ abstract class BaseReadAloudService : BaseService(), } @CallSuper - open fun newReadAloud(textChapter: TextChapter?, play: Boolean) { - textChapter?.let { + open fun newReadAloud(play: Boolean) { + textChapter?.let { textChapter -> nowSpeak = 0 readAloudNumber = textChapter.getReadLength(pageIndex) contentList.clear() diff --git a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt index f8672b30c..620566feb 100644 --- a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt @@ -8,7 +8,6 @@ import io.legado.app.help.coroutine.Coroutine import io.legado.app.model.ReadAloud import io.legado.app.model.ReadBook import io.legado.app.model.analyzeRule.AnalyzeUrl -import io.legado.app.ui.book.read.page.entities.TextChapter import io.legado.app.utils.* import kotlinx.coroutines.delay import kotlinx.coroutines.ensureActive @@ -46,10 +45,10 @@ class HttpReadAloudService : BaseReadAloudService(), player.release() } - override fun newReadAloud(textChapter: TextChapter?, play: Boolean) { + override fun newReadAloud(play: Boolean) { player.reset() playingIndex = -1 - super.newReadAloud(textChapter, play) + super.newReadAloud(play) } override fun play() {