4.3.1r21
[enigma2.git] / usr / lib / enigma2 / python / Plugins / Extensions / Browser / WebMediaPlayerProxy.py
1 from enigma import eWebMediaPlayer, eWebMediaPlayerProxy, eServiceReference
2 from Components.VolumeControl import VolumeControl
3
4 from Tools.Log import Log
5
6 class WebMediaPlayerProxy(eWebMediaPlayerProxy):
7         proxyInstance = None
8
9         def __init__(self, session, player):
10                 assert not WebMediaPlayerProxy.proxyInstance
11                 eWebMediaPlayerProxy.__init__(self)
12                 WebMediaPlayerProxy.proxyInstance = self
13                 self._session = session
14                 self.player = player
15
16         def setVideoWindow(self, x, y, width, height):
17                 if self.player:
18                         if width > 0 and height > 0:
19                                 self.player.setVideoWindow(x, y, width, height)
20                         else:
21                                 self.player.resetVideoWindow()
22
23         @staticmethod
24         def register(player):
25                 proxy = WebMediaPlayerProxy(player.session, player)
26                 eWebMediaPlayer.setProxy(proxy)
27                 return proxy
28         
29         @staticmethod
30         def unregister(player):
31                 if player == WebMediaPlayerProxy.proxyInstance.player:
32                         WebMediaPlayerProxy.proxyInstance = None
33                         eWebMediaPlayer.resetProxy()
34
35         def play(self, val, isUri):
36                 Log.w("%s %s" %(val, isUri))
37                 if not self.player:
38                         return
39                 if isUri:
40                         val = val.split("#")
41                         uri = val[0]
42                         if len(val) > 1:
43                                 name = val[1]
44                         else:
45                                 name = uri.split("/")[-1]
46                         if uri.startswith("file://") or uri.startswith("/"): #Local File
47                                 if uri.lower().endswith(".ts"):
48                                         serviceType = eServiceReference.idDVB
49                                 elif uri.lower().endswith(".m2ts"):
50                                         serviceType = eServiceReference.idM2TS
51                                 else:
52                                         serviceType = eServiceReference.idGST
53                                 uri = uri.replace("file://", "")
54                                 ref = eServiceReference(serviceType, 0, uri)
55                         else:
56                                 ref = eServiceReference(eServiceReference.idURI, 0, uri)
57                                 ref.setName(name)
58                 else:
59                         ref = eServiceReference(val)
60                 if not ref.valid():
61                         return False
62                 self.stop()
63                 self.player.playStream(ref);
64                 return True
65
66         def stop(self):
67                 Log.w()
68                 if self.player:
69                         self.player.stopStream()
70                         return True
71                 return False
72
73         def setVolume(self, to):
74                 if to < 0 or to > 100 or not VolumeControl.instance:
75                         return False
76                 VolumeControl.instance.setDiscreteVolume(to)
77                 return True
78
79
80