mirror of
https://github.com/terrymacdonald/DisplayMagician.git
synced 2024-08-30 18:32:20 +00:00
Fixed audio so it allows unplugged devices
Fixes #39. This update allows unplugged devices to be used. ALlows people to plug in headphones, and allows users like @gpo123 to use HDMI audio on a currently disbled display.
This commit is contained in:
parent
81f2d08fe0
commit
953b72e6cd
@ -26,8 +26,8 @@ using System.Resources;
|
||||
[assembly: Guid("e4ceaf5e-ad01-4695-b179-31168eb74c48")]
|
||||
|
||||
// Version information
|
||||
[assembly: AssemblyVersion("2.0.1.168")]
|
||||
[assembly: AssemblyFileVersion("2.0.1.168")]
|
||||
[assembly: AssemblyVersion("2.0.1.171")]
|
||||
[assembly: AssemblyFileVersion("2.0.1.171")]
|
||||
[assembly: NeutralResourcesLanguageAttribute( "en" )]
|
||||
[assembly: CLSCompliant(true)]
|
||||
|
||||
|
@ -1326,7 +1326,9 @@ namespace DisplayMagician
|
||||
if (worstError != ShortcutValidity.Error)
|
||||
worstError = ShortcutValidity.Error;
|
||||
}
|
||||
if (audioDevice.State == DeviceState.Unplugged)
|
||||
// As per Issue #39, this causes issues on HDMI audio devices and others that *could* work if the screen was enabled.
|
||||
// Disabling this code as it is too much error checking for audio devices. The user can plug these in after the chagne and they will work.
|
||||
/*if (audioDevice.State == DeviceState.Unplugged)
|
||||
{
|
||||
logger.Warn($"ShortcutRepository/RefreshValidity: Detected audio playback device {audioDevice.FullName} is the one we want, but it is unplugged!");
|
||||
ShortcutError error = new ShortcutError();
|
||||
@ -1336,7 +1338,7 @@ namespace DisplayMagician
|
||||
_shortcutErrors.Add(error);
|
||||
if (worstError != ShortcutValidity.Error)
|
||||
worstError = ShortcutValidity.Warning;
|
||||
}
|
||||
}*/
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1399,7 +1401,9 @@ namespace DisplayMagician
|
||||
if (worstError != ShortcutValidity.Error)
|
||||
worstError = ShortcutValidity.Error;
|
||||
}
|
||||
if (captureDevice.State == DeviceState.Unplugged)
|
||||
// As per Issue #39, this causes issues on HDMI audiodevices and others that *could* work if the screen was enabled.
|
||||
// Disabling this code as it is too much error checking for capture devices. The user can plug these in after the chagne and they will work.
|
||||
/*if (captureDevice.State == DeviceState.Unplugged)
|
||||
{
|
||||
logger.Warn($"ShortcutRepository/RefreshValidity: Detected capture device {captureDevice.FullName} is the one we want, but it is unplugged!");
|
||||
ShortcutError error = new ShortcutError();
|
||||
@ -1409,7 +1413,7 @@ namespace DisplayMagician
|
||||
_shortcutErrors.Add(error);
|
||||
if (worstError != ShortcutValidity.Error)
|
||||
worstError = ShortcutValidity.Warning;
|
||||
}
|
||||
}*/
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -669,7 +669,7 @@ namespace DisplayMagician
|
||||
|
||||
}
|
||||
|
||||
// Get the list of Audio Devices currently connected and active
|
||||
// Get the list of Audio Devices currently connected or unplugged (they can be plugged back in)
|
||||
bool needToChangeAudioDevice = false;
|
||||
CoreAudioDevice rollbackAudioDevice = null;
|
||||
double rollbackAudioVolume = 50;
|
||||
@ -682,7 +682,8 @@ namespace DisplayMagician
|
||||
if (_audioController != null)
|
||||
{
|
||||
try {
|
||||
activeAudioDevices = _audioController.GetPlaybackDevices(DeviceState.Active).ToList();
|
||||
activeAudioDevices = _audioController.GetPlaybackDevices(DeviceState.Active | DeviceState.Unplugged).ToList();
|
||||
bool foundAudioDevice = false;
|
||||
if (activeAudioDevices.Count > 0)
|
||||
{
|
||||
// Change Audio Device (if one specified)
|
||||
@ -706,21 +707,30 @@ namespace DisplayMagician
|
||||
{
|
||||
logger.Info($"ShortcutRepository/RunShortcut: Changing to the {shortcutToUse.AudioDevice} audio device.");
|
||||
|
||||
|
||||
foreach (CoreAudioDevice audioDevice in activeAudioDevices)
|
||||
{
|
||||
if (audioDevice.FullName.Equals(shortcutToUse.AudioDevice))
|
||||
{
|
||||
// use the Audio Device
|
||||
audioDevice.SetAsDefault();
|
||||
foundAudioDevice = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundAudioDevice)
|
||||
{
|
||||
logger.Error($"ShortcutRepository/RunShortcut: We wanted to use {shortcutToUse.AudioDevice} audio device but it wasn't plugged in or unplugged. Unable to use so skipping setting the audio device.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Info($"ShortcutRepository/RunShortcut: We're already using the {shortcutToUse.AudioDevice} audio device so no need to change audio devices.");
|
||||
}
|
||||
|
||||
if (foundAudioDevice)
|
||||
{
|
||||
if (shortcutToUse.SetAudioVolume)
|
||||
{
|
||||
logger.Info($"ShortcutRepository/RunShortcut: Setting {shortcutToUse.AudioDevice} volume level to {shortcutToUse.AudioVolume}%.");
|
||||
@ -736,6 +746,7 @@ namespace DisplayMagician
|
||||
logger.Info($"ShortcutRepository/RunShortcut: We don't need to set the {shortcutToUse.AudioDevice} volume level.");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Info($"ShortcutRepository/RunShortcut: Shortcut does not require changing Audio Device.");
|
||||
@ -754,8 +765,9 @@ namespace DisplayMagician
|
||||
|
||||
try
|
||||
{
|
||||
// Get the list of Audio Devices currently connected
|
||||
activeCaptureDevices = _audioController.GetCaptureDevices(DeviceState.Active).ToList();
|
||||
// Get the list of Capture Devices currently connected or currently unplugged (they can be plugged back in)
|
||||
activeCaptureDevices = _audioController.GetCaptureDevices(DeviceState.Active | DeviceState.Unplugged).ToList();
|
||||
bool foundCaptureDevice = false;
|
||||
if (activeCaptureDevices.Count > 0)
|
||||
{
|
||||
|
||||
@ -784,15 +796,23 @@ namespace DisplayMagician
|
||||
{
|
||||
// use the Audio Device
|
||||
captureDevice.SetAsDefault();
|
||||
foundCaptureDevice = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundCaptureDevice)
|
||||
{
|
||||
logger.Error($"ShortcutRepository/RunShortcut: We wanted to use {shortcutToUse.CaptureDevice} capture (microphone) device but it wasn't plugged in or unplugged. Unable to use so skipping setting the capture device.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Info($"ShortcutRepository/RunShortcut: We're already using the {shortcutToUse.CaptureDevice} capture (microphone) device so no need to change capture devices.");
|
||||
}
|
||||
|
||||
if (foundCaptureDevice)
|
||||
{
|
||||
if (shortcutToUse.SetCaptureVolume)
|
||||
{
|
||||
logger.Info($"ShortcutRepository/RunShortcut: Setting {shortcutToUse.CaptureDevice} capture (microphone) level to {shortcutToUse.CaptureVolume}%.");
|
||||
@ -807,6 +827,7 @@ namespace DisplayMagician
|
||||
{
|
||||
logger.Info($"ShortcutRepository/RunShortcut: We don't need to set the {shortcutToUse.CaptureDevice} capture (microphone) volume level.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user