This tutorial shows how to add an input file and stream it using the LEADTOOLS Media Streaming SDK in a C# .NET Console application.
Overview | |
---|---|
Summary | This tutorial covers how to add input source to streaming server in a C# .NET Console application. |
Completion Time | 15 minutes |
Visual Studio Project | Download tutorial project (1 KB) |
Platform | C# .NET Console Application |
IDE | Visual Studio 2022 |
Runtime Target | .NET 6 or higher |
Development License | Download LEADTOOLS |
Try it in another language |
|
The LEADTOOLS Media Streaming Server 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 this tutorial.
Start with a copy of the project created in the Add References and Set a License tutorial. If you do not have that project, follow the steps in that tutorial to create it.
This tutorial requires the following local DLLs, which are located at <INSTALL_DIR>\LEADTOOLS23\Bin\net
Leadtools.dll
Leadtools.Core.dll
Leadtools.MediaStreaming.dll
For a complete list of which DLL files are required for your media streaming application, 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:
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 InitLEAD
method call.
static void Main(string[] args)
{
InitLEAD();
StartStreaming();
}
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:\LEADTOOLS23\Resources\Media";
server.SetNetworkProperties(netProps);
server.Start();
Console.WriteLine("Streaming server started.");
Console.WriteLine("Attempting to playback stream in default browser using: " + HttpUrl);
Process.Start(new ProcessStartInfo(HttpUrl) { UseShellExecute = true });
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();
}
Make sure to use a valid folder name for the netProps.MediaFolder
property. In the code above, "C:\LEADTOOLS23\Resources\Media" is used, but it can be changed to a different location.
Also, place a valid MP4 video file in that folder to use for testing. For this tutorial, the file DaDa_H264.mp4
can be used, which is shipped with LEADTOOLS v23 Multimedia SDK in the <INSTALL_DIR>\LEADTOOLS23\Resources\Media
folder.
Run the project by pressing F5, or by selecting Debug -> Start Debugging.
If the steps were followed correctly, the application starts streaming the video and attempts to launch the default web browser to play back the video.
This tutorial showed how to add a video source and stream it using the MediaStreaming.Server
class.