diff --git a/Lib.Audio/Controllable.cs b/Lib.Audio/Controllable.cs index 55c711c..dc644de 100644 --- a/Lib.Audio/Controllable.cs +++ b/Lib.Audio/Controllable.cs @@ -3,6 +3,7 @@ // Copyright(c) 2021 SimonG. All Rights Reserved. using System.Collections.Generic; +using System.Linq; using Lib.Audio.Interfaces; using NAudio.CoreAudioApi; @@ -11,18 +12,20 @@ namespace Lib.Audio public class Controllable : IControllable { private readonly List _audioSessionControls; - private readonly string _name; public Controllable(List audioSessionControls, string name) { _audioSessionControls = audioSessionControls; - _name = name; + Name = name; } + public string Name { get; } + public string? IconPath => _audioSessionControls.FirstOrDefault(c => !string.IsNullOrEmpty(c.IconPath))?.IconPath; + public void SetVolume(float volume) => _audioSessionControls.ForEach(c => c.SimpleAudioVolume.Volume = volume); public void Mute() => _audioSessionControls.ForEach(c => c.SimpleAudioVolume.Mute = true); public void UnMute() => _audioSessionControls.ForEach(c => c.SimpleAudioVolume.Mute = false); - public override string ToString() => _name; + public override string ToString() => Name; } } \ No newline at end of file diff --git a/Lib.Audio/Interfaces/IControllable.cs b/Lib.Audio/Interfaces/IControllable.cs index 1362f97..c28f7be 100644 --- a/Lib.Audio/Interfaces/IControllable.cs +++ b/Lib.Audio/Interfaces/IControllable.cs @@ -6,6 +6,9 @@ namespace Lib.Audio.Interfaces { public interface IControllable { + string Name { get; } + string? IconPath { get; } + void SetVolume(float volume); void Mute(); void UnMute(); diff --git a/Lib.Audio/MasterControllable.cs b/Lib.Audio/MasterControllable.cs index 7987a92..a265d70 100644 --- a/Lib.Audio/MasterControllable.cs +++ b/Lib.Audio/MasterControllable.cs @@ -2,8 +2,6 @@ // Created: 2021-04-10 // Copyright(c) 2021 SimonG. All Rights Reserved. -using System.Linq; -using System.Runtime.InteropServices; using Lib.Audio.Interfaces; using NAudio.CoreAudioApi; @@ -12,16 +10,18 @@ namespace Lib.Audio public class MasterControllable : IMasterControllable { private readonly AudioEndpointVolume _audioEndpointVolume; - private readonly string _name; private readonly IControllableCollector _controllableCollector; public MasterControllable(AudioEndpointVolume audioEndpointVolume, string name, IControllableCollector controllableCollector) { _audioEndpointVolume = audioEndpointVolume; - _name = name; + Name = name; _controllableCollector = controllableCollector; } - + + public string Name { get; } + public string? IconPath => null; + public void SetVolume(float volume) { // try @@ -46,7 +46,7 @@ namespace Lib.Audio public void Mute() => _audioEndpointVolume.Mute = true; public void UnMute() => _audioEndpointVolume.Mute = false; - public override string ToString() => _name; + public override string ToString() => Name; // public override bool Equals(object? obj) // { // if (obj is not MasterControllable masterControllable)