This tutorial shows how to add an input file and stream it using the LEADTOOLS Media Streaming SDK in a C# .NET Framework application.
Overview | |
---|---|
Summary | This tutorial covers how to add input source to streaming server in a C# .NET Framework application. |
Completion Time | 30 minutes |
Visual Studio Project | Download tutorial project (2 KB) |
Platform | Windows C# Console Application |
IDE | Visual Studio 2017, 2019 |
Development License | Download LEADTOOLS |
The LEADTOOLS Media Streaming Server class includes a multitude of advanced features, many of which are shown in the demo projects shipped with the toolkit such as the Media Streaming Server demo.
This tutorial shows that even with a few lines of code and using the Server object's default settings, it can still be a very powerful component.
Get familiar with the basic steps of creating a project by reviewing the Add References and Set a License tutorial, before working on the Add Input Source to Media Streaming Server tutorial.
In Visual Studio, create a new C# Windows Console project, and add the below necessary LEADTOOLS references.
This tutorial requires the following local DLLs, which are located at <INSTALL_DIR>\LEADTOOLS21\Bin\Dotnet4\x64
Leadtools.dll
Leadtools.MediaStreaming.dll
Note
Different SDK features require different references. For a complete list, refer to Media Streaming Files You Must Include With Your Application.
The License unlocks the features needed for the project. It must be set before any toolkit function is called. For details, including tutorials for different platforms, refer to Setting a Runtime License.
There are two types of runtime licenses:
Note
Adding LEADTOOLS NuGet and local references and setting a license are covered in more detail in the Add References and Set a License tutorial.
With the project created, the references added, and the license set, coding can begin.
In Solution Explorer, open Program.cs
, then add using Leadtools.MediaStreaming;
and using Leadtools;
to the using
block at the top.
// Using block at the top
using Leadtools;
using Leadtools.MediaStreaming;
Add a new method called StartStreaming()
, and call it in the Main
method after the SetLicense
method call.
static void StartStreaming()
{
Server server = new Server(); // Leadtools.MediaStreaming.Server
NetworkProperties netProps = server.GetNetworkProperties();
string HttpUrl = "http://" + netProps.ActualIPAddress + ":" + netProps.Port + "/DaDa_H264.mp4";
netProps.MediaFolder = @"C:\LEADTOOLS21\Media";
server.SetNetworkProperties(netProps);
server.Start();
Console.WriteLine("Streaming server started.");
Console.WriteLine("Attempting to playback stream in default browser using: " + HttpUrl);
System.Diagnostics.Process.Start(HttpUrl);
Console.WriteLine("\nPress ESC to stop server and exit...");
while (Console.ReadKey(true).Key != ConsoleKey.Escape)
Console.WriteLine("To stop server, press ESC key.");
server.Stop();
server.Dispose();
}
static void Main(string[] args)
{
SetLicense();
StartStreaming();
}
Make sure to use a valid folder name for the netProps.MediaFolder
property. In the code above, "C:\LEADTOOLS21\Media" is used, but it can changed to a different location.
Also, place a valid MP4 video file in that folder to use it for testing. For this tutorial, the file DaDa_H264.mp4
can be used, which is shipped with LEADTOOLS 21 Multimedia SDK in the <INSTALL_DIR>\LEADTOOLS21\Media
folder.
Run the project by pressing F5, or by selecting Debug -> Start Debugging.
If the steps were followed correctly, the application runs and starts streaming the video and attempts to launch the default web browser to play back the video on it.
This tutorial showed how to add a video source and stream it using the MediaStreaming.Server
class.