You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
2.3 KiB
65 lines
2.3 KiB
// Author: Simon Gockner
|
|
// Created: 2021-04-10
|
|
// Copyright(c) 2021 SimonG. All Rights Reserved.
|
|
|
|
using Lib.Audio.Interfaces;
|
|
using NAudio.CoreAudioApi;
|
|
|
|
namespace Lib.Audio
|
|
{
|
|
public class MasterControllable : IMasterControllable
|
|
{
|
|
private readonly AudioEndpointVolume _audioEndpointVolume;
|
|
private readonly IControllableCollector _controllableCollector;
|
|
|
|
public MasterControllable(AudioEndpointVolume audioEndpointVolume, string name, IControllableCollector controllableCollector)
|
|
{
|
|
_audioEndpointVolume = audioEndpointVolume;
|
|
Name = name;
|
|
_controllableCollector = controllableCollector;
|
|
}
|
|
|
|
public bool IsValid { get; set; }
|
|
public string ExecutablePath { get; } = "";
|
|
public string Name { get; }
|
|
public string? IconPath => null;
|
|
|
|
public void SetVolume(float volume)
|
|
{
|
|
// try
|
|
// {
|
|
// // _audioEndpointVolume.MasterVolumeLevelScalar = volume;
|
|
// MasterControllable? masterControllable = _controllableCollector.Controllables.OfType<MasterControllable>().FirstOrDefault(c => c.Equals(this));
|
|
// if (masterControllable != null)
|
|
// masterControllable._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 float GetVolume()
|
|
{
|
|
throw new System.NotImplementedException();
|
|
}
|
|
|
|
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);
|
|
// }
|
|
}
|
|
} |