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

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

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

Loading…
Cancel
Save