Page 1 of 1

How do I use the function "libvlc_event_attach"?

Posted: 18 Jul 2014 16:19
by Smoke
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?

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

Posted: 18 Jul 2014 17:40
by mangokm40
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);

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

Posted: 19 Jul 2014 07:31
by Smoke
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?

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

Posted: 21 Jul 2014 18:04
by mangokm40
// 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
}

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

Posted: 23 Jul 2014 00:43
by Smoke
// 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.