mirror of
https://github.com/ppy/osu
synced 2025-01-19 04:20:59 +00:00
Update AudioDevicesOptions when devices are found or lost
This commit hooks up AudioDevicesOptions to the new events exposed by the AudioManager of osu-framework. The device list is now updated when new devices become available or are lost.
This commit is contained in:
parent
8394e2ff38
commit
d79c8b9695
@ -14,6 +14,7 @@ namespace osu.Game.Overlays.Options.Sections.Audio
|
||||
protected override string Header => "Devices";
|
||||
|
||||
private AudioManager audio;
|
||||
private OptionDropDown<string> dropdown;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(AudioManager audio)
|
||||
@ -21,21 +22,40 @@ namespace osu.Game.Overlays.Options.Sections.Audio
|
||||
this.audio = audio;
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
base.Dispose(isDisposing);
|
||||
|
||||
audio.OnNewDevice -= onDeviceChanged;
|
||||
audio.OnLostDevice -= onDeviceChanged;
|
||||
}
|
||||
|
||||
private void updateItems()
|
||||
{
|
||||
var deviceItems = new List<KeyValuePair<string, string>>();
|
||||
deviceItems.Add(new KeyValuePair<string, string>("Default", string.Empty));
|
||||
deviceItems.AddRange(audio.AudioDeviceNames.Select(d => new KeyValuePair<string, string>(d, d)));
|
||||
dropdown.Items = deviceItems;
|
||||
}
|
||||
|
||||
private void onDeviceChanged(string name) => updateItems();
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
var deviceItems = new List<KeyValuePair<string, string>>();
|
||||
deviceItems.Add(new KeyValuePair<string, string>("Default", string.Empty));
|
||||
deviceItems.AddRange(audio.GetDeviceNames().Select(d => new KeyValuePair<string, string>(d, d)));
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new OptionDropDown<string>()
|
||||
dropdown = new OptionDropDown<string>()
|
||||
{
|
||||
Items = deviceItems,
|
||||
Bindable = audio.AudioDevice
|
||||
},
|
||||
};
|
||||
|
||||
updateItems();
|
||||
|
||||
audio.OnNewDevice += onDeviceChanged;
|
||||
audio.OnLostDevice += onDeviceChanged;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user