diff --git a/Lib.Audio/Interfaces/IMasterControllable.cs b/Lib.Audio/Interfaces/IMasterControllable.cs new file mode 100644 index 0000000..54c2af1 --- /dev/null +++ b/Lib.Audio/Interfaces/IMasterControllable.cs @@ -0,0 +1,11 @@ +// Author: Simon Gockner +// Created: 2021-04-10 +// Copyright(c) 2021 SimonG. All Rights Reserved. + +namespace Lib.Audio.Interfaces +{ + public interface IMasterControllable : IControllable + { + + } +} \ No newline at end of file diff --git a/Lib.Audio/MasterControllable.cs b/Lib.Audio/MasterControllable.cs new file mode 100644 index 0000000..b1ea1d1 --- /dev/null +++ b/Lib.Audio/MasterControllable.cs @@ -0,0 +1,45 @@ +// Author: Simon Gockner +// Created: 2021-04-10 +// Copyright(c) 2021 SimonG. All Rights Reserved. + +using System.Runtime.InteropServices; +using Lib.Audio.Interfaces; +using NAudio.CoreAudioApi; + +namespace Lib.Audio +{ + public class MasterControllable : IMasterControllable + { + private readonly AudioEndpointVolume _audioEndpointVolume; + private readonly string _name; + + public MasterControllable(AudioEndpointVolume audioEndpointVolume, string name) + { + _audioEndpointVolume = audioEndpointVolume; + _name = name; + } + + public void SetVolume(float volume) + { + try + { + _audioEndpointVolume.MasterVolumeLevelScalar = volume; + } + catch (InvalidComObjectException) + { + // MasterControllable? masterControllable = _controllableCollector.Controllables.OfType().FirstOrDefault(c => c.Equals(this)); + // if (masterControllable != null) + // masterControllable._audioEndpointVolume.MasterVolumeLevelScalar = volume; + } + catch (COMException) + { + + } + } + + public void Mute() => _audioEndpointVolume.Mute = true; + public void UnMute() => _audioEndpointVolume.Mute = false; + + public override string ToString() => _name; + } +} \ No newline at end of file diff --git a/Mystify/Installers/AudioInstaller.cs b/Mystify/Installers/AudioInstaller.cs index 2e9d4f5..6ef9b50 100644 --- a/Mystify/Installers/AudioInstaller.cs +++ b/Mystify/Installers/AudioInstaller.cs @@ -23,6 +23,7 @@ namespace Mystify.Installers container.Register(); container.Register(); container.Register(); + container.Register(); container.Register(); //controls