From aa983db038481f61160e8ac2004d57a6bc97a250 Mon Sep 17 00:00:00 2001 From: David Reid Date: Fri, 14 Jan 2022 19:03:52 +1000 Subject: [PATCH] Core Audio: Stop the device when interruption_began is posted. Public issue https://github.com/mackron/miniaudio/issues/400 --- miniaudio.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/miniaudio.h b/miniaudio.h index f674f088..dbdd950c 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -32520,6 +32520,17 @@ static ma_result ma_device__untrack__coreaudio(ma_device* pDevice) case AVAudioSessionInterruptionTypeBegan: { ma_log_postf(ma_device_get_log(m_pDevice), MA_LOG_LEVEL_INFO, "[Core Audio] Interruption: AVAudioSessionInterruptionTypeBegan\n"); + + /* + Core Audio will have stopped the internal device automatically, but we need explicitly + stop it at a higher level to ensure miniaudio-specific state is updated for consistency. + */ + ma_device_stop(m_pDevice); + + /* + Fire the notification after the device has been stopped to ensure it's in the correct + state when the notification handler is invoked. + */ ma_device__on_notification_interruption_began(m_pDevice); } break;