pull/34/head
kunfei 5 years ago
parent fe10c289e9
commit 0361ed8b18
  1. 3
      app/src/main/java/io/legado/app/service/BaseReadAloudService.kt
  2. 7
      app/src/main/java/io/legado/app/service/HttpReadAloudService.kt
  3. 2
      app/src/main/java/io/legado/app/service/TTSReadAloudService.kt
  4. 6
      app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudConfigDialog.kt

@ -39,7 +39,7 @@ abstract class BaseReadAloudService : BaseService(),
private lateinit var mFocusRequest: AudioFocusRequest
private var broadcastReceiver: BroadcastReceiver? = null
private var mediaSessionCompat: MediaSessionCompat? = null
private var pause = false
var pause = false
var title: String = ""
private var subtitle: String = ""
val contentList = arrayListOf<String>()
@ -203,7 +203,6 @@ abstract class BaseReadAloudService : BaseService(),
* @return 音频焦点
*/
fun requestFocus(): Boolean {
MediaHelp.playSilentSound(this)
val request: Int = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
audioManager.requestAudioFocus(mFocusRequest)
} else {

@ -8,8 +8,6 @@ import io.legado.app.constant.Bus
import io.legado.app.utils.getPrefInt
import io.legado.app.utils.getPrefString
import io.legado.app.utils.postEvent
import kotlinx.coroutines.launch
import org.jetbrains.anko.toast
class HttpReadAloudService : BaseReadAloudService(),
MediaPlayer.OnPreparedListener,
@ -57,7 +55,6 @@ class HttpReadAloudService : BaseReadAloudService(),
}
override fun upSpeechRate(reset: Boolean) {
mediaPlayer.stop()
play()
}
@ -81,6 +78,7 @@ class HttpReadAloudService : BaseReadAloudService(),
override fun onPrepared(mp: MediaPlayer?) {
super.play()
if (pause) return
mp?.start()
textChapter?.let {
if (readAloudNumber + 1 > it.getReadLength(pageIndex + 1)) {
@ -92,8 +90,7 @@ class HttpReadAloudService : BaseReadAloudService(),
}
override fun onError(mp: MediaPlayer?, what: Int, extra: Int): Boolean {
launch { toast("播放出错") }
return false
return true
}
override fun onCompletion(mp: MediaPlayer?) {

@ -10,6 +10,7 @@ import io.legado.app.R
import io.legado.app.constant.AppConst
import io.legado.app.constant.Bus
import io.legado.app.help.IntentHelp
import io.legado.app.help.MediaHelp
import io.legado.app.utils.getPrefBoolean
import io.legado.app.utils.getPrefInt
import io.legado.app.utils.postEvent
@ -68,6 +69,7 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener
return
}
if (requestFocus()) {
MediaHelp.playSilentSound(this)
super.play()
for (i in nowSpeak until contentList.size) {
if (i == 0) {

@ -95,6 +95,12 @@ class ReadAloudConfigDialog : DialogFragment() {
ReadAloud.stop(requireContext())
ReadAloud.aloudClass = ReadAloud.getReadAloudClass()
}
"ttsSpeechPer" -> {
if (BaseReadAloudService.isRun) {
ReadAloud.stop(requireContext())
postEvent(Bus.READ_ALOUD_BUTTON, true)
}
}
}
}

Loading…
Cancel
Save