- add icon path and name as property

master
Simon G 5 years ago
parent 8a0ad228cb
commit 24ef6cb00a
  1. 9
      Lib.Audio/Controllable.cs
  2. 3
      Lib.Audio/Interfaces/IControllable.cs
  3. 10
      Lib.Audio/MasterControllable.cs

@ -3,6 +3,7 @@
// Copyright(c) 2021 SimonG. All Rights Reserved. // Copyright(c) 2021 SimonG. All Rights Reserved.
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using Lib.Audio.Interfaces; using Lib.Audio.Interfaces;
using NAudio.CoreAudioApi; using NAudio.CoreAudioApi;
@ -11,18 +12,20 @@ namespace Lib.Audio
public class Controllable : IControllable public class Controllable : IControllable
{ {
private readonly List<AudioSessionControl> _audioSessionControls; private readonly List<AudioSessionControl> _audioSessionControls;
private readonly string _name;
public Controllable(List<AudioSessionControl> audioSessionControls, string name) public Controllable(List<AudioSessionControl> audioSessionControls, string name)
{ {
_audioSessionControls = audioSessionControls; _audioSessionControls = audioSessionControls;
_name = name; Name = name;
} }
public string Name { get; }
public string? IconPath => _audioSessionControls.FirstOrDefault(c => !string.IsNullOrEmpty(c.IconPath))?.IconPath;
public void SetVolume(float volume) => _audioSessionControls.ForEach(c => c.SimpleAudioVolume.Volume = volume); public void SetVolume(float volume) => _audioSessionControls.ForEach(c => c.SimpleAudioVolume.Volume = volume);
public void Mute() => _audioSessionControls.ForEach(c => c.SimpleAudioVolume.Mute = true); public void Mute() => _audioSessionControls.ForEach(c => c.SimpleAudioVolume.Mute = true);
public void UnMute() => _audioSessionControls.ForEach(c => c.SimpleAudioVolume.Mute = false); public void UnMute() => _audioSessionControls.ForEach(c => c.SimpleAudioVolume.Mute = false);
public override string ToString() => _name; public override string ToString() => Name;
} }
} }

@ -6,6 +6,9 @@ namespace Lib.Audio.Interfaces
{ {
public interface IControllable public interface IControllable
{ {
string Name { get; }
string? IconPath { get; }
void SetVolume(float volume); void SetVolume(float volume);
void Mute(); void Mute();
void UnMute(); void UnMute();

@ -2,8 +2,6 @@
// Created: 2021-04-10 // Created: 2021-04-10
// Copyright(c) 2021 SimonG. All Rights Reserved. // Copyright(c) 2021 SimonG. All Rights Reserved.
using System.Linq;
using System.Runtime.InteropServices;
using Lib.Audio.Interfaces; using Lib.Audio.Interfaces;
using NAudio.CoreAudioApi; using NAudio.CoreAudioApi;
@ -12,16 +10,18 @@ namespace Lib.Audio
public class MasterControllable : IMasterControllable public class MasterControllable : IMasterControllable
{ {
private readonly AudioEndpointVolume _audioEndpointVolume; private readonly AudioEndpointVolume _audioEndpointVolume;
private readonly string _name;
private readonly IControllableCollector _controllableCollector; private readonly IControllableCollector _controllableCollector;
public MasterControllable(AudioEndpointVolume audioEndpointVolume, string name, IControllableCollector controllableCollector) public MasterControllable(AudioEndpointVolume audioEndpointVolume, string name, IControllableCollector controllableCollector)
{ {
_audioEndpointVolume = audioEndpointVolume; _audioEndpointVolume = audioEndpointVolume;
_name = name; Name = name;
_controllableCollector = controllableCollector; _controllableCollector = controllableCollector;
} }
public string Name { get; }
public string? IconPath => null;
public void SetVolume(float volume) public void SetVolume(float volume)
{ {
// try // try
@ -46,7 +46,7 @@ namespace Lib.Audio
public void Mute() => _audioEndpointVolume.Mute = true; public void Mute() => _audioEndpointVolume.Mute = true;
public void UnMute() => _audioEndpointVolume.Mute = false; public void UnMute() => _audioEndpointVolume.Mute = false;
public override string ToString() => _name; public override string ToString() => Name;
// public override bool Equals(object? obj) // public override bool Equals(object? obj)
// { // {
// if (obj is not MasterControllable masterControllable) // if (obj is not MasterControllable masterControllable)

Loading…
Cancel
Save