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:
Thomas Müller 2017-02-11 16:29:33 +01:00
parent 8394e2ff38
commit d79c8b9695

View File

@ -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;
}
}
}