From 610334404daab4b66bc849c9591fb185e208911e Mon Sep 17 00:00:00 2001 From: Simon G Date: Thu, 8 Apr 2021 14:57:55 +0200 Subject: [PATCH] - introduce controllable collector --- Lib.Audio/ControllableCollector.cs | 28 +++++++++++++++++++ .../IControllableCollectorFactory.cs | 13 +++++++++ .../Interfaces/IControllableCollector.cs | 13 +++++++++ 3 files changed, 54 insertions(+) create mode 100644 Lib.Audio/ControllableCollector.cs create mode 100644 Lib.Audio/Factories/IControllableCollectorFactory.cs create mode 100644 Lib.Audio/Interfaces/IControllableCollector.cs diff --git a/Lib.Audio/ControllableCollector.cs b/Lib.Audio/ControllableCollector.cs new file mode 100644 index 0000000..95f524c --- /dev/null +++ b/Lib.Audio/ControllableCollector.cs @@ -0,0 +1,28 @@ +// Author: Gockner, Simon +// Created: 2021-04-08 +// Copyright(c) 2021 SimonG. All Rights Reserved. + +using System.Collections.Generic; +using System.Linq; +using Lib.Audio.Factories; +using Lib.Audio.Interfaces; +using NAudio.CoreAudioApi; + +namespace Lib.Audio +{ + public class ControllableCollector : IControllableCollector + { + private readonly IControllableFactory _controllableFactory; + + public ControllableCollector(IControllableFactory controllableFactory) => _controllableFactory = controllableFactory; + + public List Controllables => CreateControllables(); + private List CreateControllables() + { + MMDeviceEnumerator deviceEnumerator = new(); + MMDeviceCollection? audioDevices = deviceEnumerator.EnumerateAudioEndPoints(DataFlow.All, DeviceState.Active); + + return audioDevices.Select(a => _controllableFactory.Create(a.AudioSessionManager.AudioSessionControl)).ToList(); + } + } +} \ No newline at end of file diff --git a/Lib.Audio/Factories/IControllableCollectorFactory.cs b/Lib.Audio/Factories/IControllableCollectorFactory.cs new file mode 100644 index 0000000..b1c3792 --- /dev/null +++ b/Lib.Audio/Factories/IControllableCollectorFactory.cs @@ -0,0 +1,13 @@ +// Author: Gockner, Simon +// Created: 2021-04-08 +// Copyright(c) 2021 SimonG. All Rights Reserved. + +using Lib.Audio.Interfaces; + +namespace Lib.Audio.Factories +{ + public interface IControllableCollectorFactory + { + IControllableCollector Create(); + } +} \ No newline at end of file diff --git a/Lib.Audio/Interfaces/IControllableCollector.cs b/Lib.Audio/Interfaces/IControllableCollector.cs new file mode 100644 index 0000000..9a1f5f7 --- /dev/null +++ b/Lib.Audio/Interfaces/IControllableCollector.cs @@ -0,0 +1,13 @@ +// Author: Gockner, Simon +// Created: 2021-04-08 +// Copyright(c) 2021 SimonG. All Rights Reserved. + +using System.Collections.Generic; + +namespace Lib.Audio.Interfaces +{ + public interface IControllableCollector + { + List Controllables { get; } + } +} \ No newline at end of file