pull/525/head
gedoor 5 years ago
parent bbd2cdba47
commit 41980888ea
  1. 4
      app/src/main/java/io/legado/app/help/CrashHandler.kt
  2. 31
      app/src/main/java/io/legado/app/service/TTSReadAloudService.kt

@ -8,7 +8,7 @@ import android.os.Handler
import android.os.Looper
import android.util.Log
import android.widget.Toast
import io.legado.app.service.TTSReadAloudService
import io.legado.app.service.help.ReadAloud
import io.legado.app.utils.FileUtils
import java.io.PrintWriter
import java.io.StringWriter
@ -49,7 +49,7 @@ class CrashHandler(val context: Context) : Thread.UncaughtExceptionHandler {
* uncaughtException 回调函数
*/
override fun uncaughtException(thread: Thread, ex: Throwable) {
TTSReadAloudService.clearTTS()
ReadAloud.stop(context)
handleException(ex)
mDefaultHandler?.uncaughtException(thread, ex)
}

@ -19,20 +19,8 @@ import java.util.*
class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener {
companion object {
private var textToSpeech: TextToSpeech? = null
private var ttsInitFinish = false
fun clearTTS() {
textToSpeech?.let {
it.stop()
it.shutdown()
}
textToSpeech = null
ttsInitFinish = false
}
}
private var textToSpeech: TextToSpeech? = null
private var ttsInitFinish = false
private val ttsUtteranceListener = TTSUtteranceListener()
override fun onCreate() {
@ -47,14 +35,23 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener
stopSelf()
}
override fun onDestroy() {
super.onDestroy()
clearTTS()
}
@Synchronized
private fun initTts() {
ttsInitFinish = false
textToSpeech = TextToSpeech(this, this)
}
override fun onDestroy() {
super.onDestroy()
clearTTS()
@Synchronized
fun clearTTS() {
textToSpeech?.stop()
textToSpeech?.shutdown()
textToSpeech = null
ttsInitFinish = false
}
override fun onInit(status: Int) {

Loading…
Cancel
Save