Processing Ajax...

Title
Close Dialog

Message

Confirm
Close Dialog

Confirm
Close Dialog

Confirm
Close Dialog

Show error message if audio device is missing

Description
Checks for the audio device you set on line 11 and shows a dialog box if it's missing.
Language
C#.net
Minimum Version
Created By
Keith Lammers (BFS)
Contributors
-
Date Created
Apr 21, 2022
Date Last Modified
Apr 28, 2022

Scripted Function (Macro) Code

using System;
using System.Drawing;

public static class DisplayFusionFunction
{
	public static void Run(IntPtr windowHandle)
	{
		while (true)
		{
			// Set the full audio device name here
			string audioDeviceToCheck = "ASUS VG289 (NVIDIA High Definition Audio)";
			
			// Get the audio device
			// There's a bug where it sometimes returns nothing, so this will loop a few times until it gets an answer
			string[] audioDevices = BFS.Audio.GetPlaybackDevices();
			for (int i = 0; i < 3; i++)
			{
				if (audioDevices.Length == 0)
				{
					BFS.General.ThreadWait(500);
					audioDevices = BFS.Audio.GetPlaybackDevices();
				}
				else
				{
					break;	
				}
			}
			
			
			// Loop through them to check for the specified device
			bool audioDeviceFound = false;			
			
			foreach (string device in audioDevices)
			{
				// If the specified device matches to one in the array, mark it as found and break out of this loop
				if (device.ToLower() == audioDeviceToCheck.ToLower())
				{
					audioDeviceFound = true;
					break;
				}
			}
			
			// Show an error dialog if the device wasn't found
			if (!audioDeviceFound)
			{
				BFS.Dialog.ShowMessageError("Audio device missing: " + audioDeviceToCheck);
			}		
			
			// Wait 60 seconds
			BFS.General.ThreadWait(60000);
		}
	}
}