Esempio n. 1
0
        public DirectShowDevices GetDirectShowDevices()
        {
            DirectShowDevices devices = new DirectShowDevices();

            Run("-hide_banner -list_devices true -f dshow -i dummy");

            string output = Output.ToString();

            string[] lines   = output.Lines();
            bool     isAudio = false;
            Regex    regex   = new Regex(@"\[dshow @ \w+\] +""(.+)""", RegexOptions.Compiled | RegexOptions.CultureInvariant);

            foreach (string line in lines)
            {
                if (line.Contains("] DirectShow video devices"))
                {
                    isAudio = false;
                    continue;
                }
                else if (line.Contains("] DirectShow audio devices"))
                {
                    isAudio = true;
                    continue;
                }

                Match match = regex.Match(line);

                if (match.Success)
                {
                    if (line.EndsWith("\" (video)"))
                    {
                        isAudio = false;
                    }
                    else if (line.EndsWith("\" (audio)"))
                    {
                        isAudio = true;
                    }

                    string deviceName = match.Groups[1].Value;

                    if (isAudio)
                    {
                        devices.AudioDevices.Add(deviceName);
                    }
                    else
                    {
                        devices.VideoDevices.Add(deviceName);
                    }
                }
            }

            return(devices);
        }
        public DirectShowDevices GetDirectShowDevices()
        {
            DirectShowDevices devices = new DirectShowDevices();

            Run("-list_devices true -f dshow -i dummy");

            string output = Output.ToString();

            string[] lines   = output.Lines();
            bool     isVideo = true;
            Regex    regex   = new Regex(@"\[dshow @ \w+\]  ""(.+)""", RegexOptions.Compiled | RegexOptions.CultureInvariant);

            foreach (string line in lines)
            {
                if (line.Contains("] DirectShow video devices", StringComparison.InvariantCulture))
                {
                    isVideo = true;
                    continue;
                }

                if (line.Contains("] DirectShow audio devices", StringComparison.InvariantCulture))
                {
                    isVideo = false;
                    continue;
                }

                Match match = regex.Match(line);

                if (match.Success)
                {
                    string value = match.Groups[1].Value;

                    if (isVideo)
                    {
                        devices.VideoDevices.Add(value);
                    }
                    else
                    {
                        devices.AudioDevices.Add(value);
                    }
                }
            }

            return(devices);
        }