From b25124d7cc3c5e94568e41babca6d9f9d7ec1747 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 26 Aug 2019 17:29:25 +0800 Subject: [PATCH] up --- .../io/legado/app/service/ReadAloudService.kt | 28 +++++++++++++++++++ .../app/ui/readbook/config/ReadAloudDialog.kt | 2 ++ 2 files changed, 30 insertions(+) diff --git a/app/src/main/java/io/legado/app/service/ReadAloudService.kt b/app/src/main/java/io/legado/app/service/ReadAloudService.kt index 281a3bba0..ddfaae1f8 100644 --- a/app/src/main/java/io/legado/app/service/ReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/ReadAloudService.kt @@ -75,6 +75,22 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, AudioManage } } + fun prevParagraph(context: Context) { + if (isRun) { + val intent = Intent(context, ReadAloudService::class.java) + intent.action = "prevParagraph" + context.startService(intent) + } + } + + fun nextParagraph(context: Context) { + if (isRun) { + val intent = Intent(context, ReadAloudService::class.java) + intent.action = "nextParagraph" + context.startService(intent) + } + } + fun upTtsSpeechRate(context: Context) { if (isRun) { val intent = Intent(context, ReadAloudService::class.java) @@ -144,6 +160,8 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, AudioManage "pause" -> pauseReadAloud(true) "resume" -> resumeReadAloud() "upTtsSpeechRate" -> upSpeechRate(true) + "prevParagraph" -> prevP() + "nextParagraph" -> nextP() else -> stopSelf() } } @@ -211,6 +229,16 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, AudioManage } } + private fun prevP() { + nowSpeak++ + playTTS() + } + + private fun nextP() { + nowSpeak-- + playTTS() + } + /** * 初始化MediaSession */ diff --git a/app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudDialog.kt b/app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudDialog.kt index c964b162e..29314fc51 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudDialog.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudDialog.kt @@ -115,6 +115,8 @@ class ReadAloudDialog : DialogFragment() { } iv_stop.onClick { ReadAloudService.stop(requireContext()) } iv_play_pause.onClick { postEvent(Bus.READ_ALOUD_BUTTON, true) } + iv_play_prev.onClick { ReadAloudService.prevParagraph(requireContext()) } + iv_play_next.onClick { ReadAloudService.nextParagraph(requireContext()) } } private fun upPlayState(state: Int) {