# Changing audio output when the default audio playback device changes?

**URL:** <https://discourse.libsdl.org/t/changing-audio-output-when-the-default-audio-playback-device-changes/22399>\
**Category:** SDL Development\
**Created:** [May 17, 2017, 10:55am UTC](https://discourse.libsdl.org/t/changing-audio-output-when-the-default-audio-playback-device-changes/22399 "2017-05-17T10:55:01Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![AntTheAlchemist](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/antthealchemist/32/3894_2.png) [@AntTheAlchemist](https://discourse.libsdl.org/u/AntTheAlchemist)\
**Post date:** [May 17, 2017, 10:55am UTC](https://discourse.libsdl.org/t/changing-audio-output-when-the-default-audio-playback-device-changes/22399/1 "2017-05-17T10:55:02Z")

</div>

Recently purchased a new system which has multiple audio devices: on board sound, and HDMI sound. HDMI goes to in-built monitor speakers, and on board sound goes so amplified speakers. I like to swap between the two, and most apps change their output on-the-fly when I change the default playback device in Windows 10.

When my SDL app initializes, it chooses the correct default playback device, but the output doesn’t change to the new default audio device. Can I get notification in SDL about an audio device change? I was hoping SDL\_AudioDeviceEvent would trigger, but it doesn’t. I assume that closing the audio down and re-opening it would change to the new default device? I’m using SDL\_Mixer, but I don’t think that’s an issue.

---

<div class="post-metadata">

**Author:** ![icculus](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/icculus/32/81_2.png) [@icculus](https://discourse.libsdl.org/u/icculus)\
**Post date:** [May 18, 2017, 8:21pm UTC](https://discourse.libsdl.org/t/changing-audio-output-when-the-default-audio-playback-device-changes/22399/2 "2017-05-18T20:21:40Z")

</div>

> I assume that closing the audio down and re-opening it would change to the new default device?

In many cases, SDL will quietly move to new default audio devices on your behalf _if you’ve opened the default device_. If you’ve opened a specific one by name, even if happened to be the system’s default device, it won’t migrate.

This depends on the audio target, though, and some platforms and audio APIs are nicer about this than others (some won’t do it at all, some do it without SDL’s intervention, some SDL handles it internally). What platform are you using?

Also: assuming the platform supports it, SDL _will_ tell you as audio devices come and go, but we don’t have an event to tell you when the default device changes at the moment; currently we prefer to handle that special case transparently for your app, if it’s possible to be handled.

(In cases where it can’t be handled, closing the default device and reopening it _should_ give you the new default device. If anything I said here is proving untrue, it’s possibly an SDL bug and I want to hear about it, though!)

---

<div class="post-metadata">

**Author:** ![AntTheAlchemist](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/antthealchemist/32/3894_2.png) [@AntTheAlchemist](https://discourse.libsdl.org/u/AntTheAlchemist)\
**Post date:** [June 29, 2017, 10:18pm UTC](https://discourse.libsdl.org/t/changing-audio-output-when-the-default-audio-playback-device-changes/22399/3 "2017-06-29T22:18:48Z")

</div>

Hi Ryan,

Thanks for giving this attention. I’ve taken another look and it is most certainly not changing the sound device output live when I change default in the operating system. I have to exit and re-run my game to force it to switch output, or close audio and re-open audio; but there’s no event that tells me when default audio has changed? I’ve tested this on many other games and it works as expected (I’m not sure of said games were using SDL2 though, I can dig deeper?).

Does it matter that I’m using SDL\_Mixer?

I’m using Windows10, i686-w64-mingw32, 2.0.5 pre-compiled lib. Not sure what else you need to know.

Thanks,

-Anthony

---

<div class="post-metadata">

**Author:** ![icculus](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/icculus/32/81_2.png) [@icculus](https://discourse.libsdl.org/u/icculus)\
**Post date:** [June 30, 2017, 6:04pm UTC](https://discourse.libsdl.org/t/changing-audio-output-when-the-default-audio-playback-device-changes/22399/4 "2017-06-30T18:04:30Z")

</div>

> I’m using Windows10, i686-w64-mingw32, 2.0.5 pre-compiled lib. Not sure what else you need to know.

This should start working for you in 2.0.6 (or right now in revision control), because the new WASAPI target definitely supports this.

---

<div class="post-metadata">

**Author:** ![oviano](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/o/b38774/32.png) [@oviano](https://discourse.libsdl.org/u/oviano)\
**Post date:** [October 30, 2019, 6:38am UTC](https://discourse.libsdl.org/t/changing-audio-output-when-the-default-audio-playback-device-changes/22399/5 "2019-10-30T06:38:57Z")

</div>

I am finding on macOS that it chooses the correct default audio device when you open the audio with the NULL parameter, but when you change the audio device using the menubar it doesn’t change within SDL.

I am tracking the audio device added/removed events, and these work in situations such as turning on or off bluetooth headphones in that if I react to these events by closing and reopening the audio (again with NULL) then it does switch between internal speakers and headphones, but there doesn’t seem to be away of having it respond to manual changes to the default audio device.

This is macOS 10.15 and SDL 2.0.10. Could this be addressed? Or maybe we could have that event and then my existing changes should just work by tracking this new event too.

---

<div class="post-metadata">

**Author:** ![icculus](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/icculus/32/81_2.png) [@icculus](https://discourse.libsdl.org/u/icculus)\
**Post date:** [November 2, 2019, 3:01am UTC](https://discourse.libsdl.org/t/changing-audio-output-when-the-default-audio-playback-device-changes/22399/6 "2019-11-02T03:01:40Z")

</div>

> [@oviano](#):
>
> This is macOS 10.15 and SDL 2.0.10. Could this be addressed? Or maybe we could have that event and then my existing changes should just work by tracking this new event too.

I’m pretty sure this used to work; I’ve opened a bug to look into this further here:

> <https://github.com/libsdl-org/SDL/issues/3443>
>
> \# This bug report was migrated from our old Bugzilla tracker.
> 
> \*\*Reported in ver…sion:\*\* HG 2.0
> \*\*Reported for operating system, platform:\*\* macOS 10.15, x86\_64
> 
> \# Comments on the original bug report:
> 
> On 2019-11-02 03:01:14 +0000, Ryan C. Gordon wrote:
> 
> \> As mentioned here...
> \> 
> \> https://discourse.libsdl.org/t/changing-audio-output-when-the-default-audio-playback-device-changes/22399/5
> \> 
> \> ...I'm not sure if this was \_never\_ supported or it broke at some point, but I think it makes sense for the NULL audio device to mean "the current system default" that seamlessly moves between devices as the user selects a new one in System Preferences (or plugs in headphones or connects a bluetooth speaker), etc.
> \> 
> \> The WASAPI backend works like this (using an SDL\_AudioStream to adjust behind the scenes, if the new device suddenly needs different input parameters than the SDL audio callback was providing).
> \> 
> \> Right now our CoreAudio code picks the correct system default device when you open NULL, but it apparently doesn't migrate as the default changes (but I need to look into that to see if it used to).
> \> 
> \> Obviously if the user picked a specific, non-NULL device, we shouldn't migrate.
> \> 
> \> --ryan.
> 
> On 2020-03-29 06:02:22 +0000, Ryan C. Gordon wrote:
> 
> \> 
> \> Fixed in https://hg.libsdl.org/SDL/rev/682e469ffeed
> \> 
> \> Turns out we need to track the system default device ourselves, and point the AudioQueue at a new device when it changes.
> \> 
> \> I \_think\_ the AudioQueue manages data conversions for us here, but I don't know anything beyond loopwave worked when I toggled between my MacBook's speakers and a pair of PowerBeats bluetooth headphones. If this turns out to be a problem, we can just swap in an SDL\_AudioStream as necessary, like we do with WASAPI.
> \> 
> \> For now I consider this bug resolved, though!
> \> 
> \> --ryan.

–ryan.

---

<div class="post-metadata">

**Author:** ![icculus](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/icculus/32/81_2.png) [@icculus](https://discourse.libsdl.org/u/icculus)\
**Post date:** [March 29, 2020, 6:08am UTC](https://discourse.libsdl.org/t/changing-audio-output-when-the-default-audio-playback-device-changes/22399/7 "2020-03-29T06:08:51Z")

</div>

> [@icculus](#):
>
> I’m pretty sure this used to work

Okay, turns out it never did.

The latest in SDL’s revision control will now switch between audio devices as you change the default in System Preferences. It should also work if the default device was a USB thing and you yank it out of the machine (as macOS should change the system default automatically then).

This is only when opening a NULL (default) device in SDL. If you open a specific device, we won’t switch to a new one on your behalf if it goes away or a default changes.

This does not alert the app with an event, we just transparently switch over to the new device. Likewise if the default recording device changes, too.

---

<div class="post-metadata">

**Author:** ![glebm](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/glebm/32/3930_2.png) [@glebm](https://discourse.libsdl.org/u/glebm)\
**Post date:** [October 23, 2025, 6:12am UTC](https://discourse.libsdl.org/t/changing-audio-output-when-the-default-audio-playback-device-changes/22399/8 "2025-10-23T06:12:11Z")

</div>

Does the device ID change when that happens?

We currently obtain the device ID in the call to `SDL_OpenAudioDevice`, save it to a global variable, and then pass it to functions that require a real device ID, such as `SDL_BindAudioStream`. If it changes, how do we update the global variable? Or is that the wrong approach?

---

<div class="post-metadata">

**Author:** ![icculus](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/icculus/32/81_2.png) [@icculus](https://discourse.libsdl.org/u/icculus)\
**Post date:** [October 28, 2025, 10:58pm UTC](https://discourse.libsdl.org/t/changing-audio-output-when-the-default-audio-playback-device-changes/22399/9 "2025-10-28T22:58:28Z")

</div>

If you opened a default device, the ID returned will not change even if the physical device it plays to does.
