fix unneeded import
[enigma2-plugins.git] / netcaster / src / bin / StreamPlayer.py
1 from enigma import eServiceReference
2 from sys import exc_info
3
4 class StreamPlayer:
5     is_playing = False
6     
7     def __init__(self,session, args = 0):
8         print " init StreamPlayer"
9         self.is_playing = False
10         self.session = session
11         self.oldService = self.session.nav.getCurrentlyPlayingServiceReference()
12         self.session.nav.event.append(self.__event)
13     
14     def __event(self, ev):
15         print "[NETcaster] EVENT ==>",ev
16
17     def play(self,stream):
18         try:
19             print "[NETcaster] start streaming %s" %stream.getURL()
20             if self.is_playing:
21                 self.stop()
22             url = stream.getURL()
23             if not url:
24                 print "no URL provided for play"
25                 return
26             print "playing stream", url
27             esref = eServiceReference("4097:0:0:0:0:0:0:0:0:0:%s" % url.replace(':', '%3a'))
28             self.session.nav.playService(esref)
29             self.is_playing = True
30         except:
31             print "[NETcaster] Failed to start: %s: %s" % exc_info()[:2]
32
33     def stop(self,text=""):
34         if self.is_playing:
35             print "[NETcaster] stop streaming",text
36             try:
37                 self.is_playing = False
38                 self.session.nav.stopService()
39                 self.session.nav.playService(self.oldService)
40             except TypeError,e:
41                 print " ERROR ",e
42                 self.exit()
43
44     def exit(self):
45         self.stop()
46