Grav
Grav

Reputation: 1724

OS X: respond to new audio device

I need to be notified, when a new audio device appears on OS X. I'm not sure where to start. Can Core Audio do this for me, or do I need to get down to a lower level with for instance IO Kit?

Upvotes: 2

Views: 358

Answers (1)

sbooth
sbooth

Reputation: 16986

You can do this by observing kAudioHardwarePropertyDevices. The code looks roughly like:

AudioObjectPropertyAddress propertyAddress = {
        .mSelector = kAudioHardwarePropertyDevices,
        .mScope = kAudioObjectPropertyScopeGlobal,
        .mElement = kAudioObjectPropertyElementMaster
    };

OSStatus result = AudioObjectAddPropertyListener(kAudioObjectSystemObject, &propertyAddress, myAudioObjectPropertyListenerProc, NULL);

In myAudioObjectPropertyListenerProc you can determine what devices are currently available.

Upvotes: 3

Related Questions