TestPresentation

Prerequisites

LibVLC.NET provides .NET bindings to the LibVLC core library (libVLC) of the VLC media player.
Since some newer LibVLC features are used LibVLC.NET requires VLC version 1.2 which can be downloaded here.

If you have installed the VLC media player (1.2) in its default location (e.g. C:\Program Files (x86)\VideoLAN\VLC) LibVLC.NET should work out of the box. To use a local copy of libVLC copy the files libvlc.dll, libvlccore.dll and the folder plugins into a folder called VLC to the location of you application. You can also specify the directory of the libVLC DLLs at runtime and provide your own directory.

Native Bindings

The libVLC tutorial from http://wiki.videolan.org/LibVLC_Tutorial#Sample_LibVLC_Code ported to LibVLC.NET/C# would look like this:

using System;
using System.Threading;
using LibVLC.NET;

class Program
{
  static void Main()
  {
    LibVLCLibrary library = LibVLCLibrary.Load(null);
    IntPtr inst, mp, m;

    inst = library.libvlc_new();                                      // Load the VLC engine 
    m = library.libvlc_media_new_location(inst, "path/to/your/file"); // Create a new item 
    mp = library.libvlc_media_player_new_from_media(m);               // Create a media player playing environement 
    library.libvlc_media_release(m);                                  // No need to keep the media now 
    library.libvlc_media_player_play(mp);                             // play the media_player 
    Thread.Sleep(10000);                                              // Let it play a bit 
    library.libvlc_media_player_stop(mp);                             // Stop playing 
    library.libvlc_media_player_release(mp);                          // Free the media_player 
    library.libvlc_release(inst);

    LibVLCLibrary.Free(library);
  }
}

This tutorial is included in the project Tutorial in the solution folder Tests.

WPF Bindings

LibVLC.NET.Presentation provides the element MediaElement which can be used to play medias:

xmlns:vlc="clr-namespace:LibVLC.NET.Presentation;assembly=LibVLC.NET.Presentation"

...

<vlc:MediaElement Source="file://path/to/my/file" />

Playback can be controlled by invoking the methods like Play, Pause or Stop on the MediaElement instance; the MediaElement instance's properties will changes in its dispatcher thread of course; but probably not immediately.

A WPF example can be found in the project TestPresentation in the solution folder Tests.

Last edited Nov 17, 2011 at 8:44 PM by boris_richter, version 20