|
|
@ -278,21 +278,29 @@ abstract class BaseReadAloudService : BaseService(), |
|
|
|
override fun onAudioFocusChange(focusChange: Int) { |
|
|
|
override fun onAudioFocusChange(focusChange: Int) { |
|
|
|
when (focusChange) { |
|
|
|
when (focusChange) { |
|
|
|
AudioManager.AUDIOFOCUS_GAIN -> { |
|
|
|
AudioManager.AUDIOFOCUS_GAIN -> { |
|
|
|
|
|
|
|
|
|
|
|
audioFocusLossTransient = false |
|
|
|
audioFocusLossTransient = false |
|
|
|
if (!pause) resumeReadAloud() |
|
|
|
if (!pause) { |
|
|
|
|
|
|
|
AppLog.put("音频焦点获得,继续朗读") |
|
|
|
|
|
|
|
resumeReadAloud() |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
AppLog.put("音频焦点获得") |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
AudioManager.AUDIOFOCUS_LOSS -> { |
|
|
|
AudioManager.AUDIOFOCUS_LOSS -> { |
|
|
|
|
|
|
|
AppLog.put("音频焦点丢失,暂停朗读") |
|
|
|
if (audioFocusLossTransient) { |
|
|
|
if (audioFocusLossTransient) { |
|
|
|
pauseReadAloud(true) |
|
|
|
pauseReadAloud(true) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
AudioManager.AUDIOFOCUS_LOSS_TRANSIENT -> { |
|
|
|
AudioManager.AUDIOFOCUS_LOSS_TRANSIENT -> { |
|
|
|
|
|
|
|
AppLog.put("音频焦点暂时丢失并会很快再次获得,暂停朗读") |
|
|
|
audioFocusLossTransient = true |
|
|
|
audioFocusLossTransient = true |
|
|
|
if (!pause) pauseReadAloud(false) |
|
|
|
if (!pause) pauseReadAloud(false) |
|
|
|
} |
|
|
|
} |
|
|
|
AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK -> { |
|
|
|
AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK -> { |
|
|
|
// 短暂丢失焦点,这种情况是被其他应用申请了短暂的焦点希望其他声音能压低音量(或者关闭声音)凸显这个声音(比如短信提示音), |
|
|
|
// 短暂丢失焦点,这种情况是被其他应用申请了短暂的焦点希望其他声音能压低音量(或者关闭声音)凸显这个声音(比如短信提示音), |
|
|
|
AppLog.put("短暂丢失焦点,不做处理") |
|
|
|
AppLog.put("音频焦点短暂丢失,不做处理") |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|