Processing Ajax...

Title
Close Dialog

Message

Confirm
Close Dialog

Confirm
Close Dialog

Confirm
Close Dialog

Toggle Multiple Default Audio Devices

Description
Allows the user to switch between two or more Audio Devices.
Language
C#.net
Minimum Version
Created By
Alexander Robson
Contributors
-
Date Created
Apr 22, 2019
Date Last Modified
Apr 22, 2019

Scripted Function (Macro) Code

using System;
using System.Windows.Forms;

public static class DisplayFusionFunction {
	public static void Run(IntPtr windowHandle) {
        /*
            Step 1: To find out the name of the Playback Devices you want to switch between.
                To find out the list of current Playback Devices you must
                uncomment the code below the comment "* Show Playback Devices *"
            Step 2: To find out the name of the current Playback Device you are currently using.
                To find out the Playback Device that you are currently using
                you must uncomment the code below the comment "* Show Current 
                Default Playback Device *"
            Step 3: Populate your list of Playback Devices you want to switch between.
                Under the comment "* Playback Device List *" you must paste your two, (or more)
                device names into the array.  Replace the current text with your own.  You must
                have a minimum of two devices for the switch to work.
        */
	
        /* Playback Device List */
	    string[] audioDevices = {"Headphones (Corsair HS60 Surround Gaming Dongle)", 
                                 "Speakers (Realtek High Definition Audio)",
                                 "23EA63 (NVIDIA High Definition Audio)"};
                                 
        string currentDevice = BFS.Audio.GetDefaultPlaybackSounds();
        string[] playbackDevices = BFS.Audio.GetPlaybackDevices();
        
        /* Show Playback Devices */
        //MessageBox.Show("Playback Devices Names:\n- " + string.Join("\n- ", playbackDevices));
        
        /* Show Current Default Playback Device */
        //MessageBox.Show("Current Default Playback Device:\n- " + currentDevice);
        
        int i;
        for (i = 0; i < audioDevices.Length; i++) {
            if (currentDevice == audioDevices[i]) {
                break;
            }
        }
        i++;
        if (i >= audioDevices.Length) {
            i = 0;
        }

        int j;
        bool foundAudioDevice = false;
        for (j = 0; j < playbackDevices.Length; j++) {
            if (audioDevices[i] == playbackDevices[j]) {
                foundAudioDevice = true;
                break;
            }
        }
        if (foundAudioDevice) {
            BFS.Audio.SetDefaultPlaybackSounds(audioDevices[i]);
            BFS.Audio.SetDefaultPlaybackCommunications(audioDevices[i]);
            /* Show Name of New Default Playback Device */
            //MessageBox.Show("New Device\n- " + audioDevices[i]);
        } else { 
            MessageBox.Show("Cannot Find New Device Named:\n- " + audioDevices[i] + "\n\nNo changes have been made.");
        }
    }
}