How do I use the function "libvlc_event_attach"?

This forum is about all development around libVLC.
Smoke
Blank Cone
Blank Cone
Posts: 11
Joined: 30 Oct 2013 05:35

How do I use the function "libvlc_event_attach"?

Postby Smoke » 18 Jul 2014 16:19

I saw the api not very clear. I am a little confusing with the parameters of callback function. They are const struct libvlc_event_t * and void *. What are they used for? are all events register one time and differentiated by "libvlc_event_t"? Or we register what we use? I saw "libvlc_event_attach" function also has a "libvlc_event_t" parameter.
And in the callback function, what is the void* used for?

mangokm40
Cone that earned his stripes
Cone that earned his stripes
Posts: 130
Joined: 20 May 2010 20:00

Re: How do I use the function "libvlc_event_attach"?

Postby mangokm40 » 18 Jul 2014 17:40

Here is my understanding. Hopefully, someone will correct my mistakes:

libvlc_media_player_t *vlcPlayer; // your media player
libvlc_event_manager_t *vlcEventManager = libvlc_media_player_event_manager(vlcPlayer); // get the event manager for your player

//Listen for MediaPlayerEndReached event and call OnEventCallBack with 2 parameters (libvlc_MediaPlayerEndReached, userDataPointer).
//The second parameter allows you to send any info you may want to the callback.
libvlc_event_attach(vlcEventManager, libvlc_MediaPlayerEndReached, OnEventCallBack, userDataPointer);

Smoke
Blank Cone
Blank Cone
Posts: 11
Joined: 30 Oct 2013 05:35

Re: How do I use the function "libvlc_event_attach"?

Postby Smoke » 19 Jul 2014 07:31

Hi, mangokm40,
Thank you for your answer.
How is the function "OnEventCallBack"? And what is the "userDataPointer"?
I think I need to write the "OnEventCallBack" function somewhere, How do I write?

mangokm40
Cone that earned his stripes
Cone that earned his stripes
Posts: 130
Joined: 20 May 2010 20:00

Re: How do I use the function "libvlc_event_attach"?

Postby mangokm40 » 21 Jul 2014 18:04

// This is the callback function
void OnEventCallBack(const libvlc_event_t eventName, void *userDataPointer) {
yourDataType *yourData = (yourDataType*) userDataPointer; // A cheesy way to transfer information into the callback function
}

Smoke
Blank Cone
Blank Cone
Posts: 11
Joined: 30 Oct 2013 05:35

Re: How do I use the function "libvlc_event_attach"?

Postby Smoke » 23 Jul 2014 00:43

// This is the callback function
void OnEventCallBack(const libvlc_event_t eventName, void *userDataPointer) {
yourDataType *yourData = (yourDataType*) userDataPointer; // A cheesy way to transfer information into the callback function
}
Thank you for your answer.
Could you give me an example, such as what I am doing now, I'd like the butten to change the back-grond-picture when the state is different. When it is playing, shows the "playing" picture. when it is pausing, shows the "pausing" picture. How could I do that.


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 11 guests