Add Input Source to Media Streaming Server - C# .NET Framework

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
Try it in another language

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.

Required Knowledge

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 - C# .NET Framework tutorial.

Create the Project and Add LEADTOOLS References

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>\LEADTOOLS22\Bin\DotNet4\x64

Note

Different SDK features require different references. For a complete list, refer to Media Streaming Files You Must Include With Your Application.

Set the License File

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:

Add the Streaming Server Code

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.

C#
// 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.

C#
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:\LEADTOOLS22\Resources\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(); 
} 

Prepare the Media Folder and File

Make sure to use a valid folder name for the netProps.MediaFolder property. In the code above, "C:\LEADTOOLS22\Resources\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 22 Multimedia SDK in the <INSTALL_DIR>\LEADTOOLS22\Resources\Media folder.

Run the Project

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.

Wrap-up

This tutorial showed how to add a video source and stream it using the MediaStreaming.Server class.

See Also

Help Version 22.0.2024.3.20
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.


Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.