-
-
Notifications
You must be signed in to change notification settings - Fork 416
Getting started
VLC is a popular, multiplatform, open-source media player that can read a wide range of media. It comes with a bunch of plugins that allows it to perform many tasks beyond just playing a video.
VLC is an executable file, but all its features are available to application developers thanks to libvlc, a C library.
The goal of this project is to provide a .Net abstraction over libvlc, allowing you to embed (lib)VLC features into your WinForms or WPF applications. In most cases, you want to embed a media player in your app, so that you can play your last summer holidays movie or play a RTSP stream from you network security camera.
Note: Now that you are familiar with those concepts, it is important to remember that when you have any issue when using this library, for example a decoding failure, it is probably not Vlc.DotNet's fault. Before posting any issue on this repository, please check with VLC before, and try upgrading the libvlc you are using.
You will need 2 things:
- The libvlc library, that you will redistribute with your application
- A Vlc.DotNet NuGet package and its dependencies :
- Vlc.DotNet.Forms : Contains a control to display a media player in a WinForm application. See
Vlc.DotNet.Forms.VlcControl
- Vlc.DotNet.Wpf : Same, but for WPF. For now, the WPF control is using the WinForm control under the hood. See
Vlc.DotNet.Wpf.VlcControl
- Vlc.DotNet.Core : Base dependency, for lower level interactions, such as file conversions, streaming... that doesn't require any control.
- Vlc.DotNet.Forms : Contains a control to display a media player in a WinForm application. See
Official NuGet packages - See Documentation here
You can find all the versions available on The official FTP. Pick a version, win32 or win64 depending on your target (or both!), and download the .zip file or the .7z .
At time of writing (2017-08-08), this library works with 2.1.x versions all the way through 3.0.0 nightly builds.
Tip : you should check your download with a tool like HashMyFile to be sure that your download has not been corrupted corrupted.
extract the archive and put these files into a folder (example: libvlc/win-x64
) that will be accessible from your application:
libvlc.dll
libvlccore.dll
- The
plugins
folder (you can remove the plugins that you are not using from that folder)
you will need to redistribute that libvlc/win-x64
folder with your application.
Be careful: You will also need to comply to VLC's licence. If I understand it correctly, it means that you must redistribute VLC's source code with your application (only my own interpretation, please refer to someone with more legal knowledge here)
Create a new project targetting the .net framework. Just install the NuGet package you picked above. The dependencies will automatically be pulled.
If you need to stream a video on the network, or anything more advanced than just displaying a media player in a WinForm or a WPF window, you should use this one.
Here is a console application that downloads a file using a media player (you could also transcode, but that's not the point here).
using System;
using System.IO;
using System.Threading;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
string libDirectory;
if (IntPtr.Size == 4)
{
// Use 32 bits library
libDirectory = Path.Combine(Environment.CurrentDirectory, "libvlc_x86");
}
else
{
// Use 64 bits library
libDirectory = Path.Combine(Environment.CurrentDirectory, "libvlc_x64");
}
var options = new string[]
{
// VLC options can be given here. Please refer to the VLC command line documentation.
};
var mediaPlayer = new Vlc.DotNet.Core.VlcMediaPlayer(new DirectoryInfo(libDirectory));
var mediaOptions = new string[]
{
":sout=#file{dst="+Path.Combine(Environment.CurrentDirectory, "output.mov")+"}",
":sout-keep"
};
mediaPlayer.SetMedia(new Uri("http://download.blender.org/peach/bigbuckbunny_movies/big_buck_bunny_480p_h264.mov"), mediaOptions);
bool playFinished = false;
mediaPlayer.PositionChanged += (sender, e) =>
{
Console.Write("\r" + Math.Floor(e.NewPosition * 100) + "%");
};
mediaPlayer.EncounteredError += (sender, e) =>
{
Console.Error.Write("An error occurred");
playFinished = true;
};
mediaPlayer.EndReached += (sender, e) => {
playFinished = true;
};
mediaPlayer.Play();
// Ugly, sorry, that's just an example...
while(!playFinished)
{
Thread.Sleep(TimeSpan.FromMilliseconds(500));
}
}
}
}
If you are creating a WinForms app that is displaying a video stream, you should use that.
To be honnest, I'm not familiar enough with WinForms so that I can't tell you how to add the Vlc control to you application. You will find an example at https://github.com/ZeBobo5/Vlc.DotNet/tree/master/src/Samples
If you are creating a Wpf app that is displaying a video stream, you should probably use that. It offers a good experience for Wpf developers, at the cost of being a little more resource-intensive.
If you need maximum performances, you can wrap Vlc.DotNet.WinForms in a WinFormHost
and use it like that.
Be aware that you will experience Airspace issues (see #296) if you need to write over the video.
Add the VlcControl in your UserControl/View and give it a name:
<Vlc:VlcControl xmlns:Vlc="clr-namespace:Vlc.DotNet.Wpf;assembly=Vlc.DotNet.Wpf" x:Name="MyControl" />
In your view constructor, after the call to InitializeComponent()
:
string vlcLibDirectory;
if (IntPtr.Size == 4)
{
// Use 32 bits library
vlcLibDirectory = new DirectoryInfo(Path.Combine(Environment.CurrentDirectory, "libvlc_x86"));
}
else
{
// Use 64 bits library
vlcLibDirectory = new DirectoryInfo(Path.Combine(Environment.CurrentDirectory, "libvlc_x64"));
}
var options = new string[]
{
// VLC options can be given here. Please refer to the VLC command line documentation.
};
this.MyControl.SourceProvider.CreatePlayer(vlcLibDirectory, options);
// Load libvlc libraries and initializes stuff. It is important that the options (if you want to pass any) and lib directory are given before calling this method.
this.MyControl.SourceProvider.MediaPlayer.Play("http://download.blender.org/peach/bigbuckbunny_movies/big_buck_bunny_480p_h264.mov");
If you have a problem and pulling your hair ( which 90% of the open issues here are about ) simply add this as arguments when creating Vlc instance, to enable Vlc log.
-vvv --extraintf=logger --verbose=2 --logfile=Logs.log
Copyright © ZeBobo5 & RexGrammer 2014