- add MasterControllable

master
Simon G 5 years ago
parent 0df7f0ecf2
commit b8946ae17f
  1. 11
      Lib.Audio/Interfaces/IMasterControllable.cs
  2. 45
      Lib.Audio/MasterControllable.cs
  3. 1
      Mystify/Installers/AudioInstaller.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
{
}
}

@ -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<MasterControllable>().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;
}
}

@ -23,6 +23,7 @@ namespace Mystify.Installers
container.Register<IDevice, Device>();
container.Register<IChannel, Channel>();
container.Register<IControllable, Controllable>();
container.Register<IMasterControllable, MasterControllable>();
container.Register<IControllableCollector, ControllableCollector>();
//controls

Loading…
Cancel
Save