Skip to content

Commit 70b7ae1

Browse files
committed
修复开启忽略音频焦点后,接通电话未暂停播放
1 parent 56a51de commit 70b7ae1

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

app/src/main/java/remix/myplayer/service/AudioFocusManager.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,13 @@ class AudioFocusManager @Inject constructor(
7171
callbacks = null
7272
abandonFocus()
7373
}
74-
}
74+
75+
fun shouldPauseForPhoneCall(): Boolean {
76+
val mode = audioManager.mode
77+
val inCall = mode == AudioManager.MODE_IN_CALL
78+
|| mode == AudioManager.MODE_IN_COMMUNICATION
79+
|| mode == AudioManager.MODE_RINGTONE
80+
Timber.v("shouldPauseForPhoneCall mode: $mode inCall: $inCall")
81+
return inCall
82+
}
83+
}

app/src/main/java/remix/myplayer/service/MusicService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1502,7 +1502,7 @@ class MusicService : BaseService(),
15021502
override fun onFocusLost() {
15031503
Timber.v("onFocusLost")
15041504
val ignoreFocus = settingPrefs.ignoreAudioFocus
1505-
if (ignoreFocus) {
1505+
if (ignoreFocus && !audioFocusManager.shouldPauseForPhoneCall()) {
15061506
Timber.v("忽略音频焦点 不暂停")
15071507
return
15081508
}

0 commit comments

Comments
 (0)