Fix coreaudio module not detecting changes of the default audio device.

This commit is contained in:
Alex Man 2020-12-26 22:58:50 -08:00 committed by Mary
parent f904e2f149
commit 715dc6d199

View file

@ -145,6 +145,12 @@ static void destroy_ca(struct SoundIoPrivate *si) {
};
AudioObjectRemovePropertyListener(kAudioObjectSystemObject, &prop_address, on_devices_changed, si);
prop_address.mSelector = kAudioHardwarePropertyDefaultOutputDevice;
AudioObjectRemovePropertyListener(kAudioObjectSystemObject, &prop_address, on_devices_changed, si);
prop_address.mSelector = kAudioHardwarePropertyDefaultInputDevice;
AudioObjectRemovePropertyListener(kAudioObjectSystemObject, &prop_address, on_devices_changed, si);
prop_address.mSelector = kAudioHardwarePropertyServiceRestarted;
AudioObjectRemovePropertyListener(kAudioObjectSystemObject, &prop_address, on_service_restarted, si);
@ -1446,6 +1452,22 @@ int soundio_coreaudio_init(struct SoundIoPrivate *si) {
return SoundIoErrorSystemResources;
}
prop_address.mSelector = kAudioHardwarePropertyDefaultOutputDevice;
if ((err = AudioObjectAddPropertyListener(kAudioObjectSystemObject, &prop_address,
on_devices_changed, si)))
{
destroy_ca(si);
return SoundIoErrorSystemResources;
}
prop_address.mSelector = kAudioHardwarePropertyDefaultInputDevice;
if ((err = AudioObjectAddPropertyListener(kAudioObjectSystemObject, &prop_address,
on_devices_changed, si)))
{
destroy_ca(si);
return SoundIoErrorSystemResources;
}
prop_address.mSelector = kAudioHardwarePropertyServiceRestarted;
if ((err = AudioObjectAddPropertyListener(kAudioObjectSystemObject, &prop_address,
on_service_restarted, si)))