2023-09-16 15:34:45 -06:00
|
|
|
|
using System;
|
|
|
|
|
using System.Runtime.InteropServices;
|
2023-08-20 20:52:48 -06:00
|
|
|
|
|
|
|
|
|
namespace FocusVolumeControl.AudioSessions;
|
|
|
|
|
|
2023-09-16 15:34:45 -06:00
|
|
|
|
internal sealed class SystemSoundsAudioSession : IAudioSession
|
2023-08-20 20:52:48 -06:00
|
|
|
|
{
|
2023-09-16 15:34:45 -06:00
|
|
|
|
public SystemSoundsAudioSession(IAudioSessionControl2 sessionControl)
|
2023-08-20 20:52:48 -06:00
|
|
|
|
{
|
2023-09-16 15:34:45 -06:00
|
|
|
|
_sessionControl = sessionControl;
|
|
|
|
|
_volumeControl = (ISimpleAudioVolume)sessionControl;
|
2023-08-20 20:52:48 -06:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-16 15:34:45 -06:00
|
|
|
|
IAudioSessionControl2 _sessionControl;
|
|
|
|
|
ISimpleAudioVolume _volumeControl;
|
2023-08-20 20:52:48 -06:00
|
|
|
|
|
|
|
|
|
public string DisplayName => "System sounds";
|
|
|
|
|
public string GetIcon() => "Images/systemSounds";
|
|
|
|
|
|
|
|
|
|
public void ToggleMute()
|
|
|
|
|
{
|
2023-09-16 15:34:45 -06:00
|
|
|
|
var guid = Guid.Empty;
|
|
|
|
|
_volumeControl.SetMute(!IsMuted(), ref guid);
|
2023-08-20 20:52:48 -06:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-16 15:34:45 -06:00
|
|
|
|
public bool IsMuted()
|
|
|
|
|
{
|
|
|
|
|
_volumeControl.GetMute(out var mute);
|
|
|
|
|
return mute;
|
|
|
|
|
}
|
2023-08-20 20:52:48 -06:00
|
|
|
|
|
|
|
|
|
public void IncrementVolumeLevel(int step, int ticks)
|
|
|
|
|
{
|
2023-09-16 15:34:45 -06:00
|
|
|
|
_volumeControl.GetMasterVolume(out var level);
|
|
|
|
|
level = VolumeHelpers.GetAdjustedVolume(level, step, ticks);
|
2023-08-20 20:52:48 -06:00
|
|
|
|
|
2023-09-16 15:34:45 -06:00
|
|
|
|
var guid = Guid.Empty;
|
|
|
|
|
_volumeControl.SetMasterVolume(level, ref guid);
|
|
|
|
|
}
|
2023-08-20 20:52:48 -06:00
|
|
|
|
|
2023-09-16 15:34:45 -06:00
|
|
|
|
public int GetVolumeLevel()
|
|
|
|
|
{
|
|
|
|
|
_volumeControl.GetMasterVolume(out var level);
|
|
|
|
|
return VolumeHelpers.GetVolumePercentage(level);
|
|
|
|
|
}
|
2023-08-20 20:52:48 -06:00
|
|
|
|
}
|