DotNetBrowser supports web camera and microphone. First webcam and microphone in the list of available video/audio capture devices are used as default ones. To get information about available media stream devices such as webcam or microphone, use the MediaStreamDeviceManager API.


Audio & Video Capture Devices


The following sample demonstrates how to get the list of available audio and video capture devices:


MediaStreamDeviceManager deviceManager = browser.MediaStreamDeviceManager;
 // Get list of all available audio capture devices (microphones).
 List<MediaStreamDevice> audioCaptureDevices =
        deviceManager.GetMediaStreamDevices(MediaStreamType.AUDIO_CAPTURE);
 // Get list of all available video capture devices (webcams).
List<MediaStreamDevice> videoCaptureDevices =
        deviceManager.GetMediaStreamDevices(MediaStreamType.VIDEO_CAPTURE);


Default Audio & Video Capture Devices


First webcam and microphone in the list of available video/audio capture devices are used as default ones. To change this default behavior register your own MediaStreamDeviceProvider implementation that configures default device. In your own implementation you let the end user to select which devices should be used by default if there are more than one device is available.


C#

C#
using DotNetBrowser;
using DotNetBrowser.WPF;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

namespace DefaultMediaStreamDeviceSample
{
    /// <summary>
    /// The sample demonstrates how to get list of available audio and video capture devices,
    /// register own MediaStreamDeviceProvider to provide Chromium with default audio/video capture
    /// device to be used on a web page for working with webcam and accessing microphone.
    /// </summary>

    public class WindowMain : Window
    {
        private WPFBrowserView browserView;

        public WindowMain()
        {
            Browser browser = BrowserFactory.Create();
            browserView = new WPFBrowserView(browser);

            Content = browserView;

            Width = 1024;
            Height = 768;

            MediaStreamDeviceManager deviceManager = browser.MediaStreamDeviceManager;
            // Get list of all available audio capture devices (microphones).
            List<MediaStreamDevice> audioCaptureDevices =
                    deviceManager.GetMediaStreamDevices(MediaStreamType.AUDIO_CAPTURE);
            // Get list of all available video capture devices (webcams).
            List<MediaStreamDevice> videoCaptureDevices =
                    deviceManager.GetMediaStreamDevices(MediaStreamType.VIDEO_CAPTURE);

            // Register own provider to provide Chromium with default device.
            deviceManager.Provider = new MyMediaStreamDeviceProvider();

            this.Loaded += WindowMain_Loaded;

        }

        void WindowMain_Loaded(object sender, RoutedEventArgs e)
        {
            browserView.Browser.LoadURL("https://alexandre.alapetite.fr/doc-alex/html5-webcam/index.en.html");
        }


        private class MyMediaStreamDeviceProvider : MediaStreamDeviceProvider
        {
            public void OnRequestDefaultDevice(MediaStreamDeviceRequest request)
            {
                // Set first available device as default.
                List<MediaStreamDevice> availableDevices = request.Devices;
                if (availableDevices.Count > 0)
                {
                    MediaStreamDevice defaultDevice = availableDevices[0];
                    request.SetDefaultMediaStreamDevice(defaultDevice);
                }
            }
        }

        [STAThread]
        public static void Main()
        {
            Application app = new Application();

            WindowMain wnd = new WindowMain();
            app.Run(wnd);

            var browser = wnd.browserView.Browser;
            wnd.browserView.Dispose();
            browser.Dispose();
        }
    }
}

VB.NET

Imports System.Windows
Imports DotNetBrowser
Imports DotNetBrowser.WPF

Module Module1

    Class WindowMain
        Inherits Window

        Friend browserView As WPFBrowserView

        Sub New()
            Dim browser = BrowserFactory.Create()
            browserView = New WPFBrowserView(browser)

            Content = browserView

            Width = 1024
            Height = 768

            Dim deviceManager = browser.MediaStreamDeviceManager
            ' Get list of all available audio capture devices (microphones).
            Dim audioCaptureDevices =
                    deviceManager.GetMediaStreamDevices(MediaStreamType.AUDIO_CAPTURE)
            'Get list of all available video capture devices (webcams).
            Dim videoCaptureDevices =
                    deviceManager.GetMediaStreamDevices(MediaStreamType.VIDEO_CAPTURE)

            ' Register own provider to provide Chromium with default device.
            deviceManager.Provider = New MyMediaStreamDeviceProvider()

            AddHandler Me.Loaded, AddressOf WindowMain_Loaded
        End Sub

        Sub WindowMain_Loaded()
            browserView.Browser.LoadURL("https://alexandre.alapetite.fr/doc-alex/html5-webcam/index.en.html")
        End Sub

    End Class

    Class MyMediaStreamDeviceProvider
        Implements MediaStreamDeviceProvider

        Public Sub OnRequestDefaultDevice(request As MediaStreamDeviceRequest) Implements MediaStreamDeviceProvider.OnRequestDefaultDevice
            ' Set first available device as default.
            Dim availableDevices = request.Devices
            If (availableDevices.Count &amp;amp;gt; 0) Then
                Dim defaultDevice = availableDevices.ElementAt(0)
                request.SetDefaultMediaStreamDevice(defaultDevice)
            End If
        End Sub
    End Class

    <STAThread>
    Sub Main()
        Dim app = New Application()

        Dim wnd = New WindowMain()
        app.Run(wnd)

        Dim browser = wnd.browserView.Browser
        wnd.browserView.Dispose()
        browser.Dispose()
    End Sub

End Module