pull/2319/head
kunfei 2 years ago
parent fc84a5b9b2
commit ad8463c10c
  1. 10
      app/src/main/java/io/legado/app/help/MediaHelp.kt
  2. 2
      app/src/main/java/io/legado/app/service/AudioPlayService.kt
  3. 2
      app/src/main/java/io/legado/app/service/BaseReadAloudService.kt

@ -8,6 +8,7 @@ import androidx.media.AudioAttributesCompat
import androidx.media.AudioFocusRequestCompat import androidx.media.AudioFocusRequestCompat
import androidx.media.AudioManagerCompat import androidx.media.AudioManagerCompat
import io.legado.app.R import io.legado.app.R
import splitties.systemservices.audioManager
object MediaHelp { object MediaHelp {
@ -50,13 +51,8 @@ object MediaHelp {
/** /**
* @return 音频焦点 * @return 音频焦点
*/ */
fun requestFocus( fun requestFocus(focusRequest: AudioFocusRequestCompat): Boolean {
audioManager: AudioManager, val request = AudioManagerCompat.requestAudioFocus(audioManager, focusRequest)
focusRequest: AudioFocusRequestCompat?
): Boolean {
val request = focusRequest?.let {
AudioManagerCompat.requestAudioFocus(audioManager, focusRequest)
} ?: AudioManager.AUDIOFOCUS_REQUEST_GRANTED
return request == AudioManager.AUDIOFOCUS_REQUEST_GRANTED return request == AudioManager.AUDIOFOCUS_REQUEST_GRANTED
} }

@ -560,7 +560,7 @@ class AudioPlayService : BaseService(),
if (AppConfig.ignoreAudioFocus) { if (AppConfig.ignoreAudioFocus) {
return true return true
} }
return MediaHelp.requestFocus(audioManager, mFocusRequest) return MediaHelp.requestFocus(mFocusRequest)
} }
/** /**

@ -239,7 +239,7 @@ abstract class BaseReadAloudService : BaseService(),
if (AppConfig.ignoreAudioFocus) { if (AppConfig.ignoreAudioFocus) {
return true return true
} }
val requestFocus = MediaHelp.requestFocus(audioManager, mFocusRequest) val requestFocus = MediaHelp.requestFocus(mFocusRequest)
if (!requestFocus) { if (!requestFocus) {
toastOnUi("未获取到音频焦点") toastOnUi("未获取到音频焦点")
} }

Loading…
Cancel
Save