]> git.sesse.net Git - vlc/blob - bindings/python-ctypes/footer.py
9847e30be64a478622b52d6f9b1338747f566d78
[vlc] / bindings / python-ctypes / footer.py
1 ### Start of footer.py ###
2
3 class MediaEvent(ctypes.Structure):
4     _fields_ = [
5         ('media_name', ctypes.c_char_p),
6         ('instance_name', ctypes.c_char_p),
7         ]
8
9 class EventUnion(ctypes.Union):
10     _fields_ = [
11         ('meta_type', ctypes.c_uint),
12         ('new_child', ctypes.c_uint),
13         ('new_duration', ctypes.c_longlong),
14         ('new_status', ctypes.c_int),
15         ('media', ctypes.c_void_p),
16         ('new_state', ctypes.c_uint),
17         # Media instance
18         ('new_position', ctypes.c_float),
19         ('new_time', ctypes.c_longlong),
20         ('new_title', ctypes.c_int),
21         ('new_seekable', ctypes.c_longlong),
22         ('new_pausable', ctypes.c_longlong),
23         # FIXME: Skipped MediaList and MediaListView...
24         ('filename', ctypes.c_char_p),
25         ('new_length', ctypes.c_longlong),
26         ('media_event', MediaEvent),
27         ]
28
29 class Event(ctypes.Structure):
30     _fields_ = [
31         ('type', EventType),
32         ('object', ctypes.c_void_p),
33         ('u', EventUnion),
34         ]
35
36 # Decorator for callback methods
37 callbackmethod=ctypes.CFUNCTYPE(None, Event, ctypes.c_void_p)
38
39 # Example callback method
40 @callbackmethod
41 def debug_callback(event, data):
42     print "Debug callback method"
43     print "Event:", event.type
44     print "Data", data
45
46 if __name__ == '__main__':
47     import sys
48     import gobject
49
50     @callbackmethod
51     def end_callback(event, data):
52         print "End of stream"
53         sys.exit(0)
54
55     if sys.argv[1:]:
56         i=Instance()
57         m=i.media_new(sys.argv[1])
58         p=i.media_player_new()
59         p.set_media(m)
60         p.play()
61         # Loop
62         e=p.event_manager()
63         e.event_attach(EventType.MediaPlayerPaused, end_callback, None)
64         gobject.MainLoop().run()
65