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.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
}

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

@ -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("未获取到音频焦点")
}

Loading…
Cancel
Save