This project is read-only.

Events Example

Topics: General Discussion
Feb 27, 2014 at 10:21 PM

Thank you for this dll!! Could you give an example of capturing the events please? For example the playing event?

Mar 3, 2014 at 9:43 PM
Hi ant080880,

Sorry for the late response. I haven't been paying much attention to this project as of late.

Capturing an event from this library works the same as capturing any .NET event. Within your listening class, create a method that takes two arguments; an object, and an EventArgs (or the appropriate subclass of EventArgs - see for the specific docs on each event type).
public class MyClass {

    private IMediaPlayer player { get; set; }

    public MyClass(IVLCInstance vlc){
        player = vlc.CreateMediaPlayer();
        player.Playing += OnPlaying;

    public void OnPlaying(object sender, EventArgs e){
        // Do something
I hope this helps, and thanks for using this library!

Mar 4, 2014 at 7:55 PM
Hi Paul,

Thanks for your reply. I am have added your code but I now receive the following error when the event is called...

A callback was made on a garbage collected delegate of type 'com.ptrampert.LibVLCBind!com.ptrampert.LibVLCBind.Hooks.libvlc_callback_t::Invoke'. This may cause application crashes, corruption and data loss. When passing delegates to unmanaged code, they must be kept alive by the managed application until it is guaranteed that they will never be called.

Any ideas on how to solve this. I am fairly new to C# so it may be just me.

Mar 5, 2014 at 2:57 PM
Hi Anthony,

Given the error, I'm going to venture a guess and say you've probably failed to keep the reference to IMediaPlayer (or potentially the class you've implemented around IMediaPlayer) without disposing of the player properly. All of the interfaces in com.ptrampert.LibVLCBind implement IDisposable, because underneath, they are working with unmanaged code (libvlc is a C library). This means that whenever you are done with an instance of one of these objects, you need to somehow make sure you call "Dispose()" on them. I would need to see your source, though, to be sure.

Also, make sure you are using the most recent version of this library. If I remember correctly, I ran into this issue in early versions of this.

Also, for your convenience, here's a link to the MSDN docs on IDisposable:

If you've made sure you're not inadvertently losing references without disposing of them and you still get the error, let me know. It could be an issue with my disposal code.