From 3244cc9ccde5b98398666ac2aecc0f410531db6c Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 9 Nov 2021 11:47:14 +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 --- .../java/io/legado/app/service/BaseReadAloudService.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 9823148b4..49e2a907e 100644 --- a/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt @@ -53,7 +53,7 @@ abstract class BaseReadAloudService : BaseService(), private val mediaSessionCompat: MediaSessionCompat by lazy { MediaSessionCompat(this, "readAloud") } - private var hasFocus = requestFocus() + private var audioFocusLossTransient = false internal val contentList = arrayListOf() internal var nowSpeak: Int = 0 internal var readAloudNumber: Int = 0 @@ -280,18 +280,18 @@ abstract class BaseReadAloudService : BaseService(), when (focusChange) { AudioManager.AUDIOFOCUS_GAIN -> { AppLog.put("重新获得焦点, 恢复播放") - hasFocus = true + audioFocusLossTransient = false if (!pause) resumeReadAloud() } AudioManager.AUDIOFOCUS_LOSS -> { AppLog.put("永久丢失焦点") - if (!hasFocus) { + if (audioFocusLossTransient) { pauseReadAloud(true) } } AudioManager.AUDIOFOCUS_LOSS_TRANSIENT -> { AppLog.put("暂时丢失焦点, 暂停播放") - hasFocus = false + audioFocusLossTransient = true if (!pause) pauseReadAloud(false) } AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK -> {