From ad8463c10c06726a04d45bfb510e193e9ad67f3c Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 21 Sep 2022 22:59:49 +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/help/MediaHelp.kt | 10 +++------- .../java/io/legado/app/service/AudioPlayService.kt | 2 +- .../java/io/legado/app/service/BaseReadAloudService.kt | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/MediaHelp.kt b/app/src/main/java/io/legado/app/help/MediaHelp.kt index b84e56130..d0324646c 100644 --- a/app/src/main/java/io/legado/app/help/MediaHelp.kt +++ b/app/src/main/java/io/legado/app/help/MediaHelp.kt @@ -8,6 +8,7 @@ import androidx.media.AudioAttributesCompat import androidx.media.AudioFocusRequestCompat import androidx.media.AudioManagerCompat import io.legado.app.R +import splitties.systemservices.audioManager object MediaHelp { @@ -50,13 +51,8 @@ object MediaHelp { /** * @return 音频焦点 */ - fun requestFocus( - audioManager: AudioManager, - focusRequest: AudioFocusRequestCompat? - ): Boolean { - val request = focusRequest?.let { - AudioManagerCompat.requestAudioFocus(audioManager, focusRequest) - } ?: AudioManager.AUDIOFOCUS_REQUEST_GRANTED + fun requestFocus(focusRequest: AudioFocusRequestCompat): Boolean { + val request = AudioManagerCompat.requestAudioFocus(audioManager, focusRequest) return request == AudioManager.AUDIOFOCUS_REQUEST_GRANTED } 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 884413db0..8949774e9 100644 --- a/app/src/main/java/io/legado/app/service/AudioPlayService.kt +++ b/app/src/main/java/io/legado/app/service/AudioPlayService.kt @@ -560,7 +560,7 @@ class AudioPlayService : BaseService(), if (AppConfig.ignoreAudioFocus) { return true } - return MediaHelp.requestFocus(audioManager, mFocusRequest) + return MediaHelp.requestFocus(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 e63efc10e..2a185fa1d 100644 --- a/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt @@ -239,7 +239,7 @@ abstract class BaseReadAloudService : BaseService(), if (AppConfig.ignoreAudioFocus) { return true } - val requestFocus = MediaHelp.requestFocus(audioManager, mFocusRequest) + val requestFocus = MediaHelp.requestFocus(mFocusRequest) if (!requestFocus) { toastOnUi("未获取到音频焦点") }