pull/32/head
kunfei 5 years ago
parent 1e72cd46db
commit 759d602885
  1. 2
      app/src/main/java/io/legado/app/help/CrashHandler.kt
  2. 15
      app/src/main/java/io/legado/app/service/ReadAloudService.kt

@ -8,6 +8,7 @@ import android.os.Handler
import android.os.Looper
import android.util.Log
import android.widget.Toast
import io.legado.app.service.ReadAloudService
import java.io.File
import java.io.FileOutputStream
import java.io.PrintWriter
@ -53,6 +54,7 @@ class CrashHandler : Thread.UncaughtExceptionHandler {
* uncaughtException 回调函数
*/
override fun uncaughtException(thread: Thread, ex: Throwable) {
ReadAloudService.clearTTS()
handleException(ex)
mDefaultHandler?.uncaughtException(thread, ex)
}

@ -29,6 +29,7 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, AudioManage
companion object {
val tag: String = ReadAloudService::class.java.simpleName
var isRun = false
var textToSpeech: TextToSpeech? = null
fun play(
context: Context,
@ -69,9 +70,14 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, AudioManage
context.startService(intent)
}
}
fun clearTTS() {
textToSpeech?.stop()
textToSpeech?.shutdown()
textToSpeech = null
}
}
private var textToSpeech: TextToSpeech? = null
private var ttsIsSuccess: Boolean = false
private lateinit var audioManager: AudioManager
private lateinit var mFocusRequest: AudioFocusRequest
@ -103,12 +109,11 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, AudioManage
}
override fun onDestroy() {
textToSpeech?.stop()
textToSpeech?.shutdown()
isRun = false
super.onDestroy()
clearTTS()
unregisterReceiver(broadcastReceiver)
postEvent(Bus.ALOUD_STATE, Status.STOP)
super.onDestroy()
isRun = false
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {

Loading…
Cancel
Save