mirror of
https://github.com/osukey/osukey.git
synced 2025-08-06 08:03:52 +09: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:
@ -14,6 +14,7 @@ namespace osu.Game.Overlays.Options.Sections.Audio
|
|||||||
protected override string Header => "Devices";
|
protected override string Header => "Devices";
|
||||||
|
|
||||||
private AudioManager audio;
|
private AudioManager audio;
|
||||||
|
private OptionDropDown<string> dropdown;
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(AudioManager audio)
|
private void load(AudioManager audio)
|
||||||
@ -21,21 +22,40 @@ namespace osu.Game.Overlays.Options.Sections.Audio
|
|||||||
this.audio = 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()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
base.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[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new OptionDropDown<string>()
|
dropdown = new OptionDropDown<string>()
|
||||||
{
|
{
|
||||||
Items = deviceItems,
|
|
||||||
Bindable = audio.AudioDevice
|
Bindable = audio.AudioDevice
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
updateItems();
|
||||||
|
|
||||||
|
audio.OnNewDevice += onDeviceChanged;
|
||||||
|
audio.OnLostDevice += onDeviceChanged;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user