Quick-start manual
How to get code
It is recommended to use source code instead of SourceForge download section.
To checkout source code you must have Git. You can find more information how to use Git
here.
Typical commands to checkout current code:
git clone git://libvlcnet.git.sourceforge.net/gitroot/libvlcnet/libvlcnet
To update source code:
git pull
How to build the project
To build project you will need NAnt installed. Just run "nant" command under trunk directory of the project. Under Mac OS NAnt should be already installed together with Mono. When the project is build you can find libraries under "trunk/output" directory.
Library structure
Library consists of:
- dz.mediaplayer.vlc - main assembly with core functionality. It doesn't depend on any other presentation framework like WPF or Windows.Forms.
- dz.mediaplayer.vlc.windows - conditional assembly can help to deal with library under Windows OS without any other presentation frameworks like Windows.Forms or WPF.
- dz.mediaplayer.vlc.winforms - conditional assembly can help to deal with library under Windows OS using Windows.Forms. This also can be used with WPF.
Samples consists of:
- samples/simple-player - Windows.Forms application sample. Works fine under Windows OS, works for audio under Mac OS and by fact not stable.
- samples/mac-player - thanks to monoobjc library. More stable and clean than simple-player. But this works only under Mac OS.
Unit tests
There are not enough unit tests obviously. Something is tested, but even this small amount of code depends on underlying VLC player which is constantly changing. It is not worth it to cover everything. There are also problem that VLC as a dynamic library can be loaded only once with only one initialization. That makes part of test affect others. Any help in this area would be appreciated.
Sample code with explanation
To initialize the library and deploy libvlc itself we use VlcDeployment class. It is important to have VLC packages at the same directory as your application exe. For MacOS it should be libvlc-1.1.9-macosx.zip and for Windows livlc-1.1.9-win32.zip. These packages distributed together with sources and located under '3rd-party/libvlc' directory. Code to deploy packages follows:
using DZ.MediaPlayer;
using DZ.MediaPlayer.Vlc;
using DZ.MediaPlayer.Vlc.Deployment;
using DZ.MediaPlayer.Vlc.Common;
using DZ.MediaPlayer.Vlc.Io;
//...
public class EntryPoint {
public static void Main() {
VlcDeployment deployment = VlcDeployment.Default;
// install library if it doesn't exist
if (!deployment.CheckVlcLibraryExistence (false, false)) {
// install library
deployment.Install (true);
}
}
}
To create player we use media player factory. Factory uses string array argument to initialize libvlc library. In order to understand how to use that parameter one can refer to VLC player help by running "vlc --help" in command line. Important part is plugins directory path which always should be provided.
using DZ.MediaPlayer;
using DZ.MediaPlayer.Vlc;
using DZ.MediaPlayer.Vlc.Deployment;
using DZ.MediaPlayer.Vlc.Common;
using DZ.MediaPlayer.Vlc.Io;
//...
string path = Path.Combine (Path.GetDirectoryName (Assembly.GetEntryAssembly ().Location), "plugins");
factory = new VlcMediaLibraryFactory (new string[] { "--reset-config",
"--no-snapshot-preview",
"--aspect-ratio=16:9",
"--ignore-config",
"--intf", "rc",
"--no-osd",
"--plugin-path", path });
// tell our factory to create new version of players
factory.CreateSinglePlayers = true;
Here we create actual player object. Player class provides basic methods to Play/Pause/Stop playing and control Volume. PlayerOutput class defines where output of the player goes. In our case below that will be a file. MediaInput class is used to identify source data for the player. That can be file or network stream.
string filePath = GetTemporaryFilePath();
PlayerOutput output = new PlayerOutput();
output.Files.Add(new OutFile(filePath));
player = (Player)factory.CreatePlayer (output);
player.SetMediaInput(new MediaInput (MediaInputType.File, "/Users/rz/Movies/SampleMovie.mp4"));
player.Play();
We also can use native libvlc MRL's. And we (Libvlc.Net developers) don't need to wrap and expose all of its features. One can just use MRL to get more control over the libvlc. Please refer to "vlc --help" to get more information on MRL's.
VlcMediaLibraryFactory factory = this.CreateNewFactory(new string[] {
});
VlcSinglePlayer playerStream = (VlcSinglePlayer)factory.CreatePlayer(new PlayerOutput(":sout=#transcode{vcodec=mp4v,vb=1024,acodec=mp4a,ab=192}:standard{mux=ts,dst=127.0.0.1:8080,access=udp}"));
//
string filePath = GetTemporaryFilePath();
PlayerOutput output = new PlayerOutput();
output.Files.Add(new OutFile(filePath));
//
VlcSinglePlayer playerReceive = (VlcSinglePlayer)factory.CreatePlayer(output);
playerReceive.SetMediaInput(new MediaInput(MediaInputType.UnparsedMrl, "udp://127.0.0.1:8080"));
playerStream.Play(); // start streaming
Thread.Sleep(1000); // here we can wait for streamer to start, or use Player's EventReceiver property to subscribe to player events and know when actual streaming is started
playerReceive.Play(); // start receiving the stream