public async Task AvailableDevices(object[] devices)
        {
            // Called by JavaScript when we get the list of devices
            await Task.Delay(1);

            AudioInputDevices.Clear();

            foreach (var device in devices)
            {
                string deviceString = device.ToString();
                var    dev          = JsonSerializer.Deserialize <BrowserMediaDevice>(deviceString);
                if (dev.kind == "audioinput")
                {
                    if (dev.label.Trim() != "" && dev.deviceId.Trim() != "")
                    {
                        AudioInputDevices.Add(dev);
                    }
                }
                else if (dev.kind == "audiooutput")
                {
                    if (dev.label.Trim() != "" && dev.deviceId.Trim() != "")
                    {
                        AudioOutputDevices.Add(dev);
                    }
                }
                else if (dev.kind == "videoinput")
                {
                    if (dev.label.Trim() != "" && dev.deviceId.Trim() != "")
                    {
                        VideoInputDevices.Add(dev);
                    }
                }
                else
                {
                    var kind = dev.kind;
                }
            }

            if (AudioInputDevices.Count > 0)
            {
                AudioInputDevices = AudioInputDevices.OrderBy(o => o.label).ToList();
            }
            if (AudioOutputDevices.Count > 0)
            {
                AudioOutputDevices = AudioOutputDevices.OrderBy(o => o.label).ToList();
            }
            if (VideoInputDevices.Count > 0)
            {
                VideoInputDevices = VideoInputDevices.OrderBy(o => o.label).ToList();
            }

            await RecordingStatus("Devices");
        }
        private void MainWindow_Activated(object sender, EventArgs e)
        {
            if (_initialized)
            {
                return;
            }

            Closing += Window_Closing;

            _initialized = true;

            CreateEngine();

            Title += $" (SDK v{VideoCapture1.SDK_Version()})";
            VideoCapture1.Debug_Dir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "VisioForge");

            tmRecording.Elapsed += (senderx, args) => { UpdateRecordingTime(); };

            cbOutputFormat.SelectedIndex = 2;

            foreach (var device in VideoCapture1.Video_CaptureDevices())
            {
                VideoInputDevices.Add(device.Name);
            }

            if (VideoInputDevices.Count > 0)
            {
                cbVideoInputDevice.SelectedIndex = 0;
            }

            cbVideoInputDevice_SelectionChanged(null, null);

            foreach (var device in VideoCapture1.Audio_CaptureDevices())
            {
                AudioInputDevices.Add(device.Name);
            }

            if (AudioInputDevices.Count > 0)
            {
                cbAudioInputDevice.SelectedIndex = 0;
                cbAudioInputDevice_SelectionChanged(null, null);
            }

            AudioInputLines.Clear();

            if (!string.IsNullOrEmpty(cbAudioInputDevice.SelectedItem.ToString()))
            {
                var deviceItem =
                    VideoCapture1.Audio_CaptureDevices().FirstOrDefault(device => device.Name == cbAudioInputDevice.SelectedItem.ToString());
                if (deviceItem != null)
                {
                    foreach (var line in deviceItem.Lines)
                    {
                        AudioInputLines.Add(line);
                    }

                    if (AudioInputLines.Count > 0)
                    {
                        cbAudioInputLine.SelectedIndex = 0;
                    }
                }
            }

            string defaultAudioRenderer = string.Empty;

            foreach (string audioOutputDevice in VideoCapture1.Audio_OutputDevices())
            {
                AudioOutputDevices.Add(audioOutputDevice);

                if (audioOutputDevice.Contains("Default DirectSound Device"))
                {
                    defaultAudioRenderer = audioOutputDevice;
                }
            }

            if (AudioOutputDevices.Count > 0)
            {
                if (string.IsNullOrEmpty(defaultAudioRenderer))
                {
                    cbAudioOutputDevice.SelectedIndex = 0;
                }
                else
                {
                    cbAudioOutputDevice.SelectedItem = defaultAudioRenderer;
                }
            }

            edOutput.Text = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "VisioForge", "output.mp4");
        }