From a1348e797657bf5f841c8733df03c3f1cdd5721b Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 26 Aug 2019 12:46:18 +0800 Subject: [PATCH] up --- .../io/legado/app/service/ReadAloudService.kt | 16 +++++++++++- .../app/ui/readbook/config/ReadAloudDialog.kt | 26 ++++++++++++++++++- app/src/main/res/layout/dialog_read_aloud.xml | 2 +- 3 files changed, 41 insertions(+), 3 deletions(-) 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 e769f7991..510e5111a 100644 --- a/app/src/main/java/io/legado/app/service/ReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/ReadAloudService.kt @@ -19,6 +19,7 @@ import io.legado.app.help.MediaHelp import io.legado.app.receiver.MediaButtonReceiver import io.legado.app.service.notification.ReadAloudNotification import io.legado.app.ui.widget.page.TextChapter +import io.legado.app.utils.getPrefInt import io.legado.app.utils.postEvent import io.legado.app.utils.toast import kotlinx.coroutines.launch @@ -73,6 +74,14 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, AudioManage } } + fun upTtsSpeechRate(context: Context) { + if (isRun) { + val intent = Intent(context, ReadAloudService::class.java) + intent.action = "upTtsSpeechRate" + context.startService(intent) + } + } + fun clearTTS() { textToSpeech?.stop() textToSpeech?.shutdown() @@ -107,6 +116,7 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, AudioManage initMediaSession() initBroadcastReceiver() upMediaSessionPlaybackState() + upSpeechRate() ReadAloudNotification.upNotification(this) } @@ -132,7 +142,7 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, AudioManage } "pause" -> pauseReadAloud(true) "resume" -> resumeReadAloud() - "stop" -> stopSelf() + "upTtsSpeechRate" -> upSpeechRate() else -> stopSelf() } } @@ -189,6 +199,10 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, AudioManage } } + private fun upSpeechRate() { + textToSpeech?.setSpeechRate((this.getPrefInt("ttsSpeechRate", 5) + 5) / 10f) + } + /** * 初始化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 880e4f3d3..517e3d0f0 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 @@ -6,6 +6,7 @@ import android.view.Gravity import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.SeekBar import androidx.fragment.app.DialogFragment import io.legado.app.R import io.legado.app.constant.Bus @@ -60,7 +61,7 @@ class ReadAloudDialog : DialogFragment() { cb_by_page.isChecked = requireContext().getPrefBoolean("readAloudByPage") cb_tts_follow_sys.isChecked = requireContext().getPrefBoolean("ttsFollowSys", true) seek_tts_SpeechRate.isEnabled = !cb_tts_follow_sys.isChecked - seek_tts_SpeechRate.progress = requireContext().getPrefInt("ttsSpeechRate", 10) + seek_tts_SpeechRate.progress = requireContext().getPrefInt("ttsSpeechRate", 5) } private fun initOnChange() { @@ -73,8 +74,22 @@ class ReadAloudDialog : DialogFragment() { if (buttonView.isPressed) { requireContext().putPrefBoolean("ttsFollowSys", isChecked) seek_tts_SpeechRate.isEnabled = !isChecked + upTtsSpeechRate() } } + seek_tts_SpeechRate.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { + override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { + } + + override fun onStartTrackingTouch(seekBar: SeekBar?) { + } + + override fun onStopTrackingTouch(seekBar: SeekBar?) { + requireContext().putPrefInt("ttsSpeechRate", seek_tts_SpeechRate.progress) + upTtsSpeechRate() + } + + }) } private fun initOnClick() { @@ -97,4 +112,13 @@ class ReadAloudDialog : DialogFragment() { } } + private fun upTtsSpeechRate() { + val activity = activity + if (activity is ReadBookActivity) { + if (activity.readAloudStatus == Status.PLAY) { + ReadAloudService.pause(requireContext()) + ReadAloudService.resume(requireContext()) + } + } + } } \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_read_aloud.xml b/app/src/main/res/layout/dialog_read_aloud.xml index 0583b2894..34b644939 100644 --- a/app/src/main/res/layout/dialog_read_aloud.xml +++ b/app/src/main/res/layout/dialog_read_aloud.xml @@ -161,7 +161,7 @@ android:layout_height="30dp" android:layout_marginStart="15dp" android:layout_marginEnd="15dp" - android:max="50" /> + android:max="45" />