# Getting started

Media Blocks SDK .Net

This guide will help you get started with the Media Blocks SDK .Net.

# Installation

The SDK is available as a NuGet package. You can install it using the following command:

dotnet add package VisioForge.DotNet.MediaBlocks

Please check the general installation guide for your platform for more information.

# SDK initialization

First, we need to initialize the SDK.

using VisioForge.Core;

VisioForgeX.InitSDK();

# Pipeline creation

Now, we can create a core of our application - the Pipeline.

using VisioForge.Core.MediaBlocks;

private MediaBlocksPipeline _pipeline;

_pipeline = new MediaBlocksPipeline();

We are working with a live stream and must set the live parameter to true.

To handle the pipeline errors, you can subscribe to the OnError event.

_pipeline.OnError += (sender, args) =>
{
    Console.WriteLine(args.Message);
};

Also, you can subscribe to the OnStart and OnStop events.

# Adding blocks

Let's add some blocks to the pipeline.

Add the virtual video source block:

private VirtualVideoSourceBlock _virtualSource;

_virtualSource = new VirtualVideoSourceBlock(new VirtualVideoSourceSettings());

Add the video renderer block to show our video on the screen. Depending on the platform, you'll add a VideoView control to your window from the UI NuGet package for your platform (for example, VisioForge.DotNet.Core.UI.WPF for WPF).

private VideoRendererBlock _videoRenderer;

_videoRenderer = new VideoRendererBlock(_pipeline, VideoView1);

The VideoRendererBlock constructor has two parameters: the pipeline and the VideoView control to render the video.

# Connecting blocks

Now, we need to connect the blocks.

_pipeline.Connect(_virtualSource.Output, _videoRenderer.Input);

Each block has an Output and an Input property. You can connect the blocks using the Connect method.

Depending on the block type, it may have multiple inputs and outputs.

# Start the pipeline

To start the pipeline, call the StartAsync method.

await _pipeline.StartAsync();

You'll see the video from the virtual source on the screen.

# Stop the pipeline

To stop the pipeline, call the StopAsync method.

await _pipeline.StopAsync();

# Destroy the pipeline

To destroy the pipeline, call the Dispose method.

_pipeline.Dispose();

# De-initialize the SDK

Don't forget to de-initialize the SDK when the app exits.

VisioForgeX.DestroySDK();

# Samples

More samples are available on GitHub