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

@ -8,8 +8,6 @@ import io.legado.app.constant.Bus
import io.legado.app.utils.getPrefInt import io.legado.app.utils.getPrefInt
import io.legado.app.utils.getPrefString import io.legado.app.utils.getPrefString
import io.legado.app.utils.postEvent import io.legado.app.utils.postEvent
import kotlinx.coroutines.launch
import org.jetbrains.anko.toast
class HttpReadAloudService : BaseReadAloudService(), class HttpReadAloudService : BaseReadAloudService(),
MediaPlayer.OnPreparedListener, MediaPlayer.OnPreparedListener,
@ -57,7 +55,6 @@ class HttpReadAloudService : BaseReadAloudService(),
} }
override fun upSpeechRate(reset: Boolean) { override fun upSpeechRate(reset: Boolean) {
mediaPlayer.stop()
play() play()
} }
@ -81,6 +78,7 @@ class HttpReadAloudService : BaseReadAloudService(),
override fun onPrepared(mp: MediaPlayer?) { override fun onPrepared(mp: MediaPlayer?) {
super.play() super.play()
if (pause) return
mp?.start() mp?.start()
textChapter?.let { textChapter?.let {
if (readAloudNumber + 1 > it.getReadLength(pageIndex + 1)) { if (readAloudNumber + 1 > it.getReadLength(pageIndex + 1)) {
@ -92,8 +90,7 @@ class HttpReadAloudService : BaseReadAloudService(),
} }
override fun onError(mp: MediaPlayer?, what: Int, extra: Int): Boolean { override fun onError(mp: MediaPlayer?, what: Int, extra: Int): Boolean {
launch { toast("播放出错") } return true
return false
} }
override fun onCompletion(mp: MediaPlayer?) { 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.AppConst
import io.legado.app.constant.Bus import io.legado.app.constant.Bus
import io.legado.app.help.IntentHelp import io.legado.app.help.IntentHelp
import io.legado.app.help.MediaHelp
import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.getPrefBoolean
import io.legado.app.utils.getPrefInt import io.legado.app.utils.getPrefInt
import io.legado.app.utils.postEvent import io.legado.app.utils.postEvent
@ -68,6 +69,7 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener
return return
} }
if (requestFocus()) { if (requestFocus()) {
MediaHelp.playSilentSound(this)
super.play() super.play()
for (i in nowSpeak until contentList.size) { for (i in nowSpeak until contentList.size) {
if (i == 0) { if (i == 0) {

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

Loading…
Cancel
Save