Ian Wetherbee Ian Wetherbee - 1 year ago 105
Python Question

VLC Python EventManager callback type?

I'm having trouble attaching an event handler to tell when a song has finished playing when using the VLC Python bindings. The event_attach function is complaining about the callback type.

def __init__(self):
self.vlc = vlc.Instance()
self.vlc_playlist = self.vlc.media_list_new()
self.vlc_player = self.vlc.media_list_player_new()
self.vlc_events = self.vlc_player.event_manager()
self.vlc_events.event_attach(vlc.EventType.MediaPlayerEndReached, self.SongFinished, 1)
def SongFinished(self, *args, **kwargs):


self.vlc_events.event_attach(vlc.EventType.MediaPlayerEndReached, self.SongFinished, 1)
return libvlc_event_attach(self, i_event_type, f_callback, user_data)
ArgumentError: argument 3: <type 'exceptions.TypeError'>: wrong type


Found it, VLC.py includes a small decorator ctypes function for wrapping callbacks:

callbackmethod=ctypes.CFUNCTYPE(None, Event, ctypes.c_void_p)

To use:

def SongFinished(self, data):
    print data

.event_attach(vlc.EventType.MediaPlayerEndReached, SongFinished, 1)