pull/1319/head
gedoor 3 years ago
parent 8f7d7937fa
commit 5b732a5242
  1. 3
      app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt
  2. 6
      app/src/main/java/io/legado/app/service/BaseReadAloudService.kt
  3. 5
      app/src/main/java/io/legado/app/service/HttpReadAloudService.kt

@ -4,6 +4,7 @@ import android.content.BroadcastReceiver
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.view.KeyEvent import android.view.KeyEvent
import io.legado.app.constant.AppLog
import io.legado.app.constant.EventBus import io.legado.app.constant.EventBus
import io.legado.app.data.appDb import io.legado.app.data.appDb
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
@ -41,6 +42,7 @@ class MediaButtonReceiver : BroadcastReceiver() {
val keycode: Int = keyEvent.keyCode val keycode: Int = keyEvent.keyCode
val action: Int = keyEvent.action val action: Int = keyEvent.action
if (action == KeyEvent.ACTION_DOWN) { if (action == KeyEvent.ACTION_DOWN) {
AppLog.addLog("mediaButton $action")
when (keycode) { when (keycode) {
KeyEvent.KEYCODE_MEDIA_PREVIOUS -> { KeyEvent.KEYCODE_MEDIA_PREVIOUS -> {
if (context.getPrefBoolean("mediaButtonPerNext", false)) { if (context.getPrefBoolean("mediaButtonPerNext", false)) {
@ -86,6 +88,7 @@ class MediaButtonReceiver : BroadcastReceiver() {
LifecycleHelp.isExistActivity(AudioPlayActivity::class.java) -> LifecycleHelp.isExistActivity(AudioPlayActivity::class.java) ->
postEvent(EventBus.MEDIA_BUTTON, true) postEvent(EventBus.MEDIA_BUTTON, true)
else -> if (AppConfig.mediaButtonOnExit || LifecycleHelp.activitySize() > 0 || !isMediaKey) { else -> if (AppConfig.mediaButtonOnExit || LifecycleHelp.activitySize() > 0 || !isMediaKey) {
AppLog.addLog("readAloud start Service")
if (ReadBook.book != null) { if (ReadBook.book != null) {
ReadBook.readAloud() ReadBook.readAloud()
} else { } else {

@ -81,9 +81,9 @@ abstract class BaseReadAloudService : BaseService(),
intent?.action?.let { action -> intent?.action?.let { action ->
when (action) { when (action) {
IntentAction.play -> { IntentAction.play -> {
textChapter = ReadBook.curTextChapter
pageIndex = ReadBook.durPageIndex() pageIndex = ReadBook.durPageIndex()
newReadAloud( newReadAloud(
ReadBook.curTextChapter,
intent.getBooleanExtra("play", true) intent.getBooleanExtra("play", true)
) )
} }
@ -101,8 +101,8 @@ abstract class BaseReadAloudService : BaseService(),
} }
@CallSuper @CallSuper
open fun newReadAloud(textChapter: TextChapter?, play: Boolean) { open fun newReadAloud(play: Boolean) {
textChapter?.let { textChapter?.let { textChapter ->
nowSpeak = 0 nowSpeak = 0
readAloudNumber = textChapter.getReadLength(pageIndex) readAloudNumber = textChapter.getReadLength(pageIndex)
contentList.clear() contentList.clear()

@ -8,7 +8,6 @@ import io.legado.app.help.coroutine.Coroutine
import io.legado.app.model.ReadAloud import io.legado.app.model.ReadAloud
import io.legado.app.model.ReadBook import io.legado.app.model.ReadBook
import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.ui.book.read.page.entities.TextChapter
import io.legado.app.utils.* import io.legado.app.utils.*
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.ensureActive import kotlinx.coroutines.ensureActive
@ -46,10 +45,10 @@ class HttpReadAloudService : BaseReadAloudService(),
player.release() player.release()
} }
override fun newReadAloud(textChapter: TextChapter?, play: Boolean) { override fun newReadAloud(play: Boolean) {
player.reset() player.reset()
playingIndex = -1 playingIndex = -1
super.newReadAloud(textChapter, play) super.newReadAloud(play)
} }
override fun play() { override fun play() {

Loading…
Cancel
Save