Media

This guide gives an overview of the supported video and audio formats, describes how to control audio, get information about available web cameras and microphones, and other features.

Codecs

Google Chrome and Chromium differ in several ways, including the sets of audio and video codecs they support.

The table below displays which codecs are supported by the codebase of corresponding browsers.

  Chromium Google Chrome
AAC no yes
H.264 no yes
MP3 yes yes
MP4 no yes
Opus yes yes
Theora yes yes
Vorbis yes yes
VP8 yes yes
VP9 yes yes
WAV yes yes


As you can see in the table above, Google Chrome supports H.264, AAC, and MP4 codecs while Chromium does not. The reason is that these codecs are proprietary and cannot be used in an open-source or a commercial project without obtaining licenses from the corresponding patent holders.

Different codecs have different patent holders. For example, to use H.264, companies must acquire the license from MPEG-LA company. You can read more about their license terms on the MPEG-LA’s website.

Proprietary codecs

Patent holders do not license codecs to the software that represents only a part of the final product deployed to the end users, for example, libraries like DotNetBrowser.

To support H.264, AAC, or MP4 in your products, you need to purchase appropriate licenses and enable the following proprietary features:

engine = EngineFactory.Create(new EngineOptions.Builder
{
    RenderingMode = RenderingMode.HardwareAccelerated,
    ProprietaryFeatures = ProprietaryFeatures.H264 | ProprietaryFeatures.Aac
}.Build());

After providing the license information and enabling proprietary features, you can load web pages with the AAC, MP4, and H.264 formats, and play audio and video files, just like in Google Chrome. By default, the proprietary codecs are disabled.

The H.264 (MP4) and AAC codecs are the proprietary components. By enabling these codecs you state that you are aware that H.264 and AAC are the proprietary components, and you should have a license in order to use them. For more information, you could contact the patent holders: Via Licensing and MPEG LA. TeamDev shall not be responsible for your use of the H.264 and AAC codecs.

Video

DotNetBrowser fully supports HTML5 <video> element and can play video in the supported formats.

If the library cannot play a video, or a video format is unsupported, DotNetBrowser suggests to download the video file. For details, refer to Downloads section containing the instructions on managing downloads.

HTML5 Video

Audio

Controlling audio

Using IAudioController you can find out whether audio is playing on the loaded web page:

bool audioPlaying = browser.Audio.IsPlaying;

You can mute or unmute audio on the loaded web page if required:

browser.Audio.Muted = true;
browser.Audio.Muted = false;

To check whether audio is muted, use the following code:

bool audioMuted = browser.Audio.Muted;

Audio events

To find out whether audio has started/stopped playing on the loaded web page, you can subscribe to the following events:

browser.Audio.AudioPlaybackStarted += (s, e) => { };
browser.Audio.AudioPlaybackStopped += (s, e) => { };

DRM

Widevine

The web services like Netflix or Amazon Prime use Widevine to distribute their DRM-encoded content. Widevine is a Google proprietary component and is disabled by default. To enable it and play the DRM-encoded content, use the code sample below:

engine = EngineFactory.Create(new EngineOptions.Builder
{
    RenderingMode = RenderingMode.HardwareAccelerated,
    ProprietaryFeatures = ProprietaryFeatures.Widevine
}.Build());

Widevine is a Google proprietary component, governed by its own terms of use. For more information, refer to Widevine.

Camera & microphone

DotNetBrowser supports a web camera and microphone. You can get information about all available media stream devices using the code sample below:

IMediaDevices mediaDevices = engine.MediaDevices;

// Get all available video devices, e.g. web camera.
IEnumerable<MediaDevice> videoDevices = mediaDevices.VideoCaptureDevices;

// Get all available audio devices, e.g. microphone.
IEnumerable<MediaDevice> audioDevices = mediaDevices.AudioCaptureDevices;

Selecting a media device

You can have multiple webcams and microphones in your environment. When a web page wants to use one of them, you can use SelectMediaDeviceHandler to instruct the web page on which device to use.

The code sample below demonstrates how to select the first device from the list of available ones:

mediaDevices.SelectMediaDeviceHandler = 
    new Handler<SelectMediaDeviceParameters, SelectMediaDeviceResponse>(p =>
    {
        return SelectMediaDeviceResponse.Select(e.Devices.FirstOrDefault());
    });

The handler will not be invoked if there are no media input devices of the requested type.

If want to restrict the access to your microphone or webcam for a particular webpage, you can use RequestPermissionHandler as shown in the code sample below:

engine.Permissions.RequestPermissionHandler = 
    new Handler<RequestPermissionParameters, RequestPermissionResponse>(p => 
    {
        if (p.Type == PermissionType.AudioCapture || p.Type == PermissionType.VideoCapture)
        {
            return RequestPermissionResponse.Deny();
        }
        return RequestPermissionResponse.Grant();
    });
Go Top