Thursday, February 27, 2014

Get all audio & video devices on a machine


Hello Friends, Today I am going to show you how to get all audio & video devices on a machine, these will be loaded on form load and displayed in a comboboxlist.

Step 1
Download this .rar with the necessary .DLLs. Link below
Microsoft.Expression.Encoder.Utilities.dll, Microsoft.Expression.Encoder.Types.dll, Microsoft.Expression.Encoder.dll, Microsoft.Expression.Encoder.Api2.dll.
http://www.microsoft.com/en-in/download/details.aspx?id=18974
Extract the.DLLs to a your desktop or a folder.

Step 2
Now in visual studio create a new project named GetDevices.
Next right click GetDevices in your Solution Explorer and click Add Reference.
Now select a .Dll and press Add.
Next do this for all the other .DLLs in which I supplied you.


Step 3
Now double click on form1.
Look for namespace GetDevices, above it Replace all the text with this.
Quote:


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Expression.Encoder.Devices;
 Step 4
Go back to to Form1.cs[Design]
Add 2 combolistboxes, name one comboBox1, and the other comboBox2.
Navigate back to form1.cs[Code]
In private void Form1_Load(object sender, EventArgs e) add this code.
Quote:


public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            devices();
        }
        public void devices()
        {
 
            foreach (EncoderDevice edv in EncoderDevices.FindDevices(EncoderDeviceType.Video))
            {

                comboBox1.Items.Add(edv.Name);
            }
            foreach (EncoderDevice eda in EncoderDevices.FindDevices(EncoderDeviceType.Audio))
            {
                comboBox2.Items.Add(eda.Name);
              
            }
        }
    }

This is the snapshot for this project is.


You can download source code from here

No comments:

Post a Comment