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)
|
||||
@ -705,6 +706,7 @@ namespace DisplayMagician
|
||||
if (needToChangeAudioDevice)
|
||||
{
|
||||
logger.Info($"ShortcutRepository/RunShortcut: Changing to the {shortcutToUse.AudioDevice} audio device.");
|
||||
|
||||
|
||||
foreach (CoreAudioDevice audioDevice in activeAudioDevices)
|
||||
{
|
||||
@ -712,29 +714,38 @@ namespace DisplayMagician
|
||||
{
|
||||
// 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 (shortcutToUse.SetAudioVolume)
|
||||
if (foundAudioDevice)
|
||||
{
|
||||
logger.Info($"ShortcutRepository/RunShortcut: Setting {shortcutToUse.AudioDevice} volume level to {shortcutToUse.AudioVolume}%.");
|
||||
Task myTask = new Task(() =>
|
||||
if (shortcutToUse.SetAudioVolume)
|
||||
{
|
||||
_audioController.DefaultPlaybackDevice.SetVolumeAsync(Convert.ToDouble(shortcutToUse.AudioVolume));
|
||||
});
|
||||
myTask.Start();
|
||||
myTask.Wait(2000);
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Info($"ShortcutRepository/RunShortcut: We don't need to set the {shortcutToUse.AudioDevice} volume level.");
|
||||
}
|
||||
logger.Info($"ShortcutRepository/RunShortcut: Setting {shortcutToUse.AudioDevice} volume level to {shortcutToUse.AudioVolume}%.");
|
||||
Task myTask = new Task(() =>
|
||||
{
|
||||
_audioController.DefaultPlaybackDevice.SetVolumeAsync(Convert.ToDouble(shortcutToUse.AudioVolume));
|
||||
});
|
||||
myTask.Start();
|
||||
myTask.Wait(2000);
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Info($"ShortcutRepository/RunShortcut: We don't need to set the {shortcutToUse.AudioDevice} volume level.");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -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,29 +796,38 @@ 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 (shortcutToUse.SetCaptureVolume)
|
||||
if (foundCaptureDevice)
|
||||
{
|
||||
logger.Info($"ShortcutRepository/RunShortcut: Setting {shortcutToUse.CaptureDevice} capture (microphone) level to {shortcutToUse.CaptureVolume}%.");
|
||||
Task myTask = new Task(() =>
|
||||
if (shortcutToUse.SetCaptureVolume)
|
||||
{
|
||||
_audioController.DefaultCaptureDevice.SetVolumeAsync(Convert.ToDouble(shortcutToUse.CaptureVolume));
|
||||
});
|
||||
myTask.Start();
|
||||
myTask.Wait(2000);
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Info($"ShortcutRepository/RunShortcut: We don't need to set the {shortcutToUse.CaptureDevice} capture (microphone) volume level.");
|
||||
}
|
||||
logger.Info($"ShortcutRepository/RunShortcut: Setting {shortcutToUse.CaptureDevice} capture (microphone) level to {shortcutToUse.CaptureVolume}%.");
|
||||
Task myTask = new Task(() =>
|
||||
{
|
||||
_audioController.DefaultCaptureDevice.SetVolumeAsync(Convert.ToDouble(shortcutToUse.CaptureVolume));
|
||||
});
|
||||
myTask.Start();
|
||||
myTask.Wait(2000);
|
||||
}
|
||||
else
|
||||
{
|
||||
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