23551a1acae5e982c1a5b62c7bb26ff1c74f3ec8
[vlc.git] / python / vlrs / streamer.py
1 #!/usr/bin/python -O
2 #
3 # VideoLAN RTSP Server
4 #
5 # Author: Cyril Deguet <asmax@via.ecp.fr>
6
7 import cfg, vlc
8
9
10 class VlcError(Exception):
11     "Exception class for libvlc calls"
12     pass
13
14
15
16 class VlcStreamer:
17     "Manage a streamer with libvlc"
18     
19     def __init__(self, file, address):
20         "Create the streamer"
21         self.file = file
22         self.address = address
23         self.id = vlc.create()
24         if self.id < 0:        
25             raise VlcError
26         if vlc.init(self.id, self.file, self.address) < 0:
27             raise VlcError
28             
29     def play(self):
30         "Play the stream"
31         if vlc.play(self.id) < 0:
32             raise VlcError
33             
34     def stop(self):
35         "Stop the stream"
36         if vlc.stop(self.id) < 0:
37             raise VlcError
38             
39     def pause(self):
40         "Pause the stream"
41         if vlc.pause(self.id) < 0:
42             raise VlcError
43
44