From cd9a5bbe3905e50981c96221c59fd6e6cc0eebe5 Mon Sep 17 00:00:00 2001
From: Horis <821938089@qq.com>
Date: Sun, 18 Sep 2022 20:07:12 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/src/main/java/io/legado/app/constant/PreferKey.kt | 1 +
app/src/main/java/io/legado/app/help/config/AppConfig.kt | 2 ++
.../main/java/io/legado/app/service/AudioPlayService.kt | 8 ++++++++
.../java/io/legado/app/service/BaseReadAloudService.kt | 8 ++++++++
app/src/main/res/values-es-rES/strings.xml | 2 ++
app/src/main/res/values-ja-rJP/strings.xml | 2 ++
app/src/main/res/values-pt-rBR/strings.xml | 2 ++
app/src/main/res/values-zh-rHK/strings.xml | 2 ++
app/src/main/res/values-zh-rTW/strings.xml | 2 ++
app/src/main/res/values-zh/strings.xml | 2 ++
app/src/main/res/values/strings.xml | 2 ++
app/src/main/res/xml/pref_config_other.xml | 6 ++++++
12 files changed, 39 insertions(+)
diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt
index 42330282f..f5f640bf9 100644
--- a/app/src/main/java/io/legado/app/constant/PreferKey.kt
+++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt
@@ -112,6 +112,7 @@ object PreferKey {
const val pageTouchSlop = "pageTouchSlop"
const val showAddToShelfAlert = "showAddToShelfAlert"
const val asyncLoadImage = "asyncLoadImage"
+ const val ignoreAudioFocus = "ignoreAudioFocus"
const val cPrimary = "colorPrimary"
const val cAccent = "colorAccent"
diff --git a/app/src/main/java/io/legado/app/help/config/AppConfig.kt b/app/src/main/java/io/legado/app/help/config/AppConfig.kt
index 8b769d020..55a579868 100644
--- a/app/src/main/java/io/legado/app/help/config/AppConfig.kt
+++ b/app/src/main/java/io/legado/app/help/config/AppConfig.kt
@@ -322,6 +322,8 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
val asyncLoadImage get() = appCtx.getPrefBoolean(PreferKey.asyncLoadImage, false)
+ val ignoreAudioFocus get() = appCtx.getPrefBoolean(PreferKey.ignoreAudioFocus, false)
+
val doublePageHorizontal: String?
get() = appCtx.getPrefString(PreferKey.doublePageHorizontal)
diff --git a/app/src/main/java/io/legado/app/service/AudioPlayService.kt b/app/src/main/java/io/legado/app/service/AudioPlayService.kt
index 8078be2cd..d5b8b57a2 100644
--- a/app/src/main/java/io/legado/app/service/AudioPlayService.kt
+++ b/app/src/main/java/io/legado/app/service/AudioPlayService.kt
@@ -24,6 +24,7 @@ import io.legado.app.data.appDb
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter
import io.legado.app.help.MediaHelp
+import io.legado.app.help.config.AppConfig
import io.legado.app.help.exoplayer.ExoPlayerHelper
import io.legado.app.help.glide.ImageLoader
import io.legado.app.model.AudioPlay
@@ -442,6 +443,10 @@ class AudioPlayService : BaseService(),
* 音频焦点变化
*/
override fun onAudioFocusChange(focusChange: Int) {
+ if (AppConfig.ignoreAudioFocus) {
+ AppLog.put("忽略音频焦点处理(有声)")
+ return
+ }
when (focusChange) {
AudioManager.AUDIOFOCUS_GAIN -> {
// 重新获得焦点, 可做恢复播放,恢复后台音量的操作
@@ -541,6 +546,9 @@ class AudioPlayService : BaseService(),
* @return 音频焦点
*/
private fun requestFocus(): Boolean {
+ if (AppConfig.ignoreAudioFocus) {
+ return true
+ }
return MediaHelp.requestFocus(audioManager, mFocusRequest)
}
diff --git a/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt b/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt
index 5d88f58e8..91f09c082 100644
--- a/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt
+++ b/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt
@@ -17,6 +17,7 @@ import io.legado.app.R
import io.legado.app.base.BaseService
import io.legado.app.constant.*
import io.legado.app.help.MediaHelp
+import io.legado.app.help.config.AppConfig
import io.legado.app.help.glide.ImageLoader
import io.legado.app.model.ReadAloud
import io.legado.app.model.ReadBook
@@ -230,6 +231,9 @@ abstract class BaseReadAloudService : BaseService(),
* @return 音频焦点
*/
fun requestFocus(): Boolean {
+ if (AppConfig.ignoreAudioFocus) {
+ return true
+ }
val requestFocus = MediaHelp.requestFocus(audioManager, mFocusRequest)
if (!requestFocus) {
toastOnUi("未获取到音频焦点")
@@ -277,6 +281,10 @@ abstract class BaseReadAloudService : BaseService(),
* 音频焦点变化
*/
override fun onAudioFocusChange(focusChange: Int) {
+ if (AppConfig.ignoreAudioFocus) {
+ AppLog.put("忽略音频焦点处理(TTS)")
+ return
+ }
when (focusChange) {
AudioManager.AUDIOFOCUS_GAIN -> {
if (needResumeOnAudioFocusGain) {
diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml
index 0739aa62f..8f357e728 100644
--- a/app/src/main/res/values-es-rES/strings.xml
+++ b/app/src/main/res/values-es-rES/strings.xml
@@ -1029,4 +1029,6 @@
赞
踩
异步加载图片
+ 忽略音频焦点
+ 允许与其他应用同时播放音频
diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml
index 98817be18..9268538e6 100644
--- a/app/src/main/res/values-ja-rJP/strings.xml
+++ b/app/src/main/res/values-ja-rJP/strings.xml
@@ -1032,4 +1032,6 @@
赞
踩
异步加载图片
+ 忽略音频焦点
+ 允许与其他应用同时播放音频
diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml
index 17ebfb35f..3b2399cbc 100644
--- a/app/src/main/res/values-pt-rBR/strings.xml
+++ b/app/src/main/res/values-pt-rBR/strings.xml
@@ -1032,4 +1032,6 @@
赞
踩
异步加载图片
+ 忽略音频焦点
+ 允许与其他应用同时播放音频
diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml
index 432def19b..040b03b55 100644
--- a/app/src/main/res/values-zh-rHK/strings.xml
+++ b/app/src/main/res/values-zh-rHK/strings.xml
@@ -1029,4 +1029,6 @@
赞
踩
异步加载图片
+ 忽略音频焦点
+ 允许与其他应用同时播放音频
diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml
index 29aa6bcd6..47ce6617d 100644
--- a/app/src/main/res/values-zh-rTW/strings.xml
+++ b/app/src/main/res/values-zh-rTW/strings.xml
@@ -1031,4 +1031,6 @@
赞
踩
异步加载图片
+ 忽略音频焦点
+ 允许与其他应用同时播放音频
diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml
index 36df208ef..e440f7fa8 100644
--- a/app/src/main/res/values-zh/strings.xml
+++ b/app/src/main/res/values-zh/strings.xml
@@ -1031,4 +1031,6 @@
赞
踩
异步加载图片
+ 忽略音频焦点
+ 允许与其他应用同时播放音频
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 51cbafe59..cd09d3602 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1032,4 +1032,6 @@
赞
踩
异步加载图片
+ 忽略音频焦点
+ 允许与其他应用同时播放音频
diff --git a/app/src/main/res/xml/pref_config_other.xml b/app/src/main/res/xml/pref_config_other.xml
index 6a6b44c68..02aba8f9a 100644
--- a/app/src/main/res/xml/pref_config_other.xml
+++ b/app/src/main/res/xml/pref_config_other.xml
@@ -118,6 +118,12 @@
android:summary="@string/show_add_to_shelf_alert_summary"
android:title="@string/show_add_to_shelf_alert_title" />
+
+