From fd97fdf9f60aac461df5ff6e70d4ed8c68249a6f Mon Sep 17 00:00:00 2001 From: Simon G Date: Sun, 11 Apr 2021 00:43:08 +0200 Subject: [PATCH] - not really working code for master volume --- Lib.Audio/MasterControllable.cs | 43 +++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/Lib.Audio/MasterControllable.cs b/Lib.Audio/MasterControllable.cs index b1ea1d1..7987a92 100644 --- a/Lib.Audio/MasterControllable.cs +++ b/Lib.Audio/MasterControllable.cs @@ -2,6 +2,7 @@ // 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,34 +13,46 @@ namespace Lib.Audio { private readonly AudioEndpointVolume _audioEndpointVolume; private readonly string _name; + private readonly IControllableCollector _controllableCollector; - public MasterControllable(AudioEndpointVolume audioEndpointVolume, string name) + public MasterControllable(AudioEndpointVolume audioEndpointVolume, string name, IControllableCollector controllableCollector) { _audioEndpointVolume = audioEndpointVolume; _name = name; + _controllableCollector = controllableCollector; } 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) - { - - } + // try + // { + // // _audioEndpointVolume.MasterVolumeLevelScalar = volume; + // MasterControllable? masterControllable = _controllableCollector.Controllables.OfType().FirstOrDefault(c => c.Equals(this)); + // if (masterControllable != null) + // masterControllable._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; + // public override bool Equals(object? obj) + // { + // if (obj is not MasterControllable masterControllable) + // return false; + // + // return _name.Equals(masterControllable._name); + // } } } \ No newline at end of file