Processing Ajax...

Title
Close Dialog

Message

Confirm
Close Dialog

Confirm
Close Dialog

Confirm
Close Dialog

Select Audio-Device (Yes/No Dialog)

Description
I use this function to toggle between two audio-devices with minimum UI-Interaction (just Y/N-Selection instead of having to deal with Listboxes etc.) You will need to update the code and enter the names of your devices - fear not: there's even commented code to show the names, in case you don't know them!
Language
C#.net
Minimum Version
Created By
MBaas
Contributors
-
Date Created
Jun 10, 2019
Date Last Modified
Jun 10, 2019

Scripted Function (Macro) Code

using System;
using System.Drawing;
using System.Linq;

public static class DisplayFusionFunction {
    public static void Run () {
        //*** Typical usage scenario is to toggle between 2 devices - so make sure to enter the names of your devices here: (if you have problems getting them correctly, try uncommenting line 14-17)
        string[] myPreferredDevices = { "Speakers/Headphones (Realtek(R) Audio)", "Lautsprecher (5- Sennheiser USB headset)" };
        string[] devList = BFS.Audio.GetPlaybackDevices ();
        string foo = string.Concat ("Devices", String.Join (",", devList.ToArray ()));
        string currDevice = BFS.Audio.GetDefaultPlaybackSounds ();
        string[] filteredList = devList.Intersect (myPreferredDevices, StringComparer.OrdinalIgnoreCase).ToArray ();

        // Diagnosis to see name of devices etc.
        //foo = string.Concat(foo, "\n");
        //foo = string.Concat(foo, String.Join("," , filteredList.ToArray()));
        //       BFS.Dialog.ShowMessageError(foo);

        string selectedAudioDevice = "";
        bool doIt = false;

        if (filteredList.Length == 0) {
            BFS.Dialog.ShowMessageError ("No Audio Devices Found!");
        } else if (filteredList.Length == 2) {
            int i = Array.IndexOf (filteredList, currDevice);
            int j = (i == 0) ? 1 : 0;
            string msg = String.Concat ("Press Yes to switch to device ", filteredList[j]);
            doIt = BFS.Dialog.GetUserConfirm (msg);
            selectedAudioDevice = filteredList[j];
        } else {
            // Prompt to select an audio device
            selectedAudioDevice = BFS.Dialog.GetUserInputList ("Please select an audio device:", devList);
            doIt = true;
        }
        if (doIt) {
            // Set the selected device as the default playback device
            BFS.Audio.SetDefaultPlaybackSounds (selectedAudioDevice);

            // Set the selected device as the default communication device
            BFS.Audio.SetDefaultPlaybackCommunications (selectedAudioDevice);
        }
    }
}