Search code examples
opentkopenal

Handling Device change in OpenAL


I'm trying to write an application using OpenTK.OpenAL to wrap openal, and I'm concerned about how I should handle a hypothetical situation where I unplug my default audio output device (such as headphones). When I try to open my default device, it labels it "OpenAL Soft" instead of the actual device name, after opening it. And it doesn't seem to respond at all when I unplug the headphones I was using, and once they're plugged back in it just is completely quiet.


Solution

  • I just got done looking through some of OpenTK's OpenAL code. It seems like OpenTK is being as true to OpenAL as possible, they're just wrapping OpenAL calls.

    For something like a hardware disconnect event, you'd have to listen for that event from the OS. I don't believe that OpenAL has this function natively. On Windows you'd probably want to look at WM_DEVICECHANGE to determine if an audio device connected or disconnected, and from there set the device like you normally would in OpenTK.