How do you create an event with VLC1.1.4 in C# ?

This forum is about all development around libVLC.
hussam_2000
Blank Cone
Blank Cone
Posts: 65
Joined: 03 Aug 2010 21:03

How do you create an event with VLC1.1.4 in C# ?

Postby hussam_2000 » 09 Dec 2010 00:49

application: Winform
Lib: VLC1.1.4
Language: C#
problem :
i'm tryin to trigger an event in my winform C# to update the scroll bar for the player. I'm looking @ a C# wrapper that has almost all the functions in it (http://www.koders.com/csharp/fid04837E1 ... spx?s=file)

if anything relates to Events on this page it would be in the following sections

#region Event Manager Methods
[DllImport("libvlc")]
internal static extern void libvlc_event_attach(IntPtr p_event_manager, VlcEventType i_event_type, VlcCallback f_callback, IntPtr p_user_data, ref libvlc_exception_t p_exception);

[DllImport("libvlc")]
internal static extern void libvlc_event_detach(IntPtr p_event_manager, VlcEventType i_event_type, VlcCallback f_callback, IntPtr p_user_data, ref libvlc_exception_t p_exception);

[DllImport("libvlc")]
internal static extern string libvlc_event_type_name(VlcEventType event_type);

how would i create a event with this code ? is there something that im missing ? What else can i use from VLC1.1.4 to do it ?

Thank you, Sam E

hussam_2000
Blank Cone
Blank Cone
Posts: 65
Joined: 03 Aug 2010 21:03

Re: How do you create an event with VLC1.1.4 in C# ?

Postby hussam_2000 » 09 Dec 2010 16:24

Let me rephrase this… I want to update the scroll bar of my player while the video is playing and also time remaining..Etc this is all based on VLC events so where do I do this with the vlclib 1.1.4  in C#.. Any tips?

XilasZ
Developer
Developer
Posts: 189
Joined: 16 Jun 2009 20:35

Re: How do you create an event with VLC1.1.4 in C# ?

Postby XilasZ » 10 Dec 2010 14:11

you don't need to use libvlc_event* directly, the wrapper in your link as everything you need.
Just subscribe to VlcMediaPlayer.PositionChanged in your code.

hussam_2000
Blank Cone
Blank Cone
Posts: 65
Joined: 03 Aug 2010 21:03

Re: How do you create an event with VLC1.1.4 in C# ?

Postby hussam_2000 » 13 Dec 2010 17:44

Sorry !! wrong link .. i used this wrapper : http://www.helyar.net/2009/libvlc-media-player-in-c/ and i was looking @ the other link that i posted on top to import the proper event handlers and try and implement it in the new wrapper. i still cannot do it !! the example provided when you download "libvlcnet" is impossible to trace !!!

XilasZ
Developer
Developer
Posts: 189
Joined: 16 Jun 2009 20:35

Re: How do you create an event with VLC1.1.4 in C# ?

Postby XilasZ » 13 Dec 2010 23:38

What is your issue exactly ? What did you try ?

hussam_2000
Blank Cone
Blank Cone
Posts: 65
Joined: 03 Aug 2010 21:03

Re: How do you create an event with VLC1.1.4 in C# ?

Postby hussam_2000 » 15 Dec 2010 16:22

I want to update the trackbar while the video is playnging. I know VLC can trigger Events such as ( file is playing , reach end of file, clicked stop , play...) so i want to handle these events in C# ( especially updating the trackbar for the video )

hussam_2000
Blank Cone
Blank Cone
Posts: 65
Joined: 03 Aug 2010 21:03

Re: How do you create an event with VLC1.1.4 in C# ?

Postby hussam_2000 » 15 Dec 2010 23:14

[UnmanagedFunctionPoiner(CallingConvention.Cdecl)]
public delegate void VlcEventHandlerDelegate(IntPtr libvlc_event, IntPtr userData)

[DllImport("libvlc")]
internal static extern void libvlc_event_attach(IntPtr p_event_manager, VlcEventType i_event_type, VlcCallback f_callback, IntPtr p_user_data, ref libvlc_exception_t p_exception);

[DllImport("libvlc")]
internal static extern IntPtr libvlc_media_player_get_media(IntPtr p_media_player, ref libvlc_exception_t p_exception);

public void init()
{
instance = libvlc.libvlc_new(arg.length,args);
Handle = Libvlc.libvlc_media_Player_newFrom_media(media);
IntPtr p = Libvlc.libvlc_media_player_event_manager(Handle);
attachToEvent(p, new libvlc.VlcEventHandlerDelegate(Stopped),libvlc_event_type_t.libvlc_MediaPlayerStopped);
}


private void attachToEvent( IntPtr evenManager, Delegate EventHandlerDelegate, libvlc_event_type_t evenType)
{
libvlc.libvlc_event_attach(evenManager,eventType,Marshal.GetFunctionPointerForDelegate(eventHandlerDelegate),IntPtr.Zero);
}

private void Stopped ( IntPtr libvlc_event, IntPtr data)
{
//. do something
}


Doesnt crash or anything but no events are generated when i click stop

XilasZ
Developer
Developer
Posts: 189
Joined: 16 Jun 2009 20:35

Re: How do you create an event with VLC1.1.4 in C# ?

Postby XilasZ » 16 Dec 2010 17:07

i can see 2 diff between your code and my wrapper :

- i don't use Marshal.GetFunctionPointerForDelegate, i use the delegate directly

- my callback is not the same :
internal delegate void libvlc_callback_t(ref VlcEvent Event, IntPtr UserData)
where VlcEvent is a structure which match exactly libvlc_event_t (see libvlc_events.h in vlc sources for details). It contains all the data of the event (ie: position for the positionchanged event).


you should call libvlc_errmsg(), after each libvlc_*(), see if there is any error.

hussam_2000
Blank Cone
Blank Cone
Posts: 65
Joined: 03 Aug 2010 21:03

Re: How do you create an event with VLC1.1.4 in C# ?

Postby hussam_2000 » 16 Dec 2010 22:38

Thank you for putting the time into this. How and where do i use your libvlc_callback_t in the code i provided ? im really lost !

XilasZ
Developer
Developer
Posts: 189
Joined: 16 Jun 2009 20:35

Re: How do you create an event with VLC1.1.4 in C# ?

Postby XilasZ » 16 Dec 2010 22:56

libvlc_callback_t is just the name of the callback (VlcEventHandlerDelegate in your code).

the diff is the first parameter.

hussam_2000
Blank Cone
Blank Cone
Posts: 65
Joined: 03 Aug 2010 21:03

Re: How do you create an event with VLC1.1.4 in C# ?

Postby hussam_2000 » 17 Dec 2010 16:56

I got the following code :

Code: Select all

///////////////////////////////// IS THIS EVENT ATTACH CORRECT ?// [DllImport("libvlc")] public static extern void libvlc_event_attach(IntPtr p_event_manager, libvlc_event_type_t i_event_type, EventCallbackDelegate f_callback, IntPtr user_data); //////////////////////////////////but i think i should use the following when i change the callback to yours /////////////////////////////////but then how would it call [b]MediaPlayerStopped[/b][DllImport("libvlc")] public static extern void libvlc_event_attach(IntPtr p_event_manager, libvlc_event_type_t i_event_type, libvlc_callback_t f_callback, IntPtr user_data); internal delegate void libvlc_callback_t(ref libvlc_event_type_t Event, IntPtr userData); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void EventCallbackDelegate(IntPtr player); public enum libvlc_event_type_t { libvlc_MediaMetaChanged, libvlc_MediaSubItemAdded, libvlc_MediaDurationChanged, libvlc_MediaPreparsedChanged, libvlc_MediaFreed, libvlc_MediaStateChanged, libvlc_MediaPlayerNothingSpecial, libvlc_MediaPlayerOpening, libvlc_MediaPlayerBuffering, libvlc_MediaPlayerPlaying, libvlc_MediaPlayerPaused, libvlc_MediaPlayerStopped, libvlc_MediaPlayerForward, libvlc_MediaPlayerBackward, libvlc_MediaPlayerEndReached, libvlc_MediaPlayerEncounteredError, libvlc_MediaPlayerTimeChanged, libvlc_MediaPlayerPositionChanged, libvlc_MediaPlayerSeekableChanged, libvlc_MediaPlayerPausableChanged, libvlc_MediaListItemAdded, libvlc_MediaListWillAddItem, libvlc_MediaListItemDeleted, libvlc_MediaListWillDeleteItem, libvlc_MediaListViewItemAdded, libvlc_MediaListViewWillAddItem, libvlc_MediaListViewItemDeleted, libvlc_MediaListViewWillDeleteItem, libvlc_MediaListPlayerPlayed, libvlc_MediaListPlayerNextItemSet, libvlc_MediaListPlayerStopped, libvlc_MediaDiscovererStarted, libvlc_MediaDiscovererEnded }
so..

Code: Select all

public VlcMediaPlayer(VlcMedia media, VlcInstance instance) { Handle = LibVlc.libvlc_media_player_new_from_media(media.media); IntPtr pFirstMediaPlayerInternalEventManager = LibVlc.libvlc_media_player_event_manager(Handle); ////// HOW WOULD MY libvlc_event_attach() look like ?////////////////// } private void MediaPlayerStopped(IntPtr data) { int i = 0; i++; }
Thank you !!!


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 17 guests