4.3.1r21
[enigma2.git] / usr / lib / enigma2 / python / Plugins / Extensions / Browser / MoviePlayer.py
1 # -*- coding: UTF-8 -*-
2
3 from Screens.Screen import Screen
4 from Screens.ChoiceBox import ChoiceBox
5 from Screens.InfoBarGenerics import InfoBarNotifications, InfoBarSeek, InfoBarShowHide, InfoBarAudioSelection, InfoBarCueSheetSupport, InfoBarSubtitleSupport
6
7 from Components.ActionMap import ActionMap
8
9 from Helpers import debug
10
11 class MoviePlayer(Screen, InfoBarNotifications, InfoBarSeek, InfoBarShowHide, InfoBarAudioSelection, InfoBarCueSheetSupport, InfoBarSubtitleSupport):
12         ENABLE_RESUME_SUPPORT = True
13         ALLOW_SUSPEND = True
14
15         def __init__(self, session, service, restoreService = True, infoCallback = None, getNextService = None, getPrevService = None, stopCallback = None, pauseCallback = None):
16                 Screen.__init__(self, session)
17                 InfoBarNotifications.__init__(self)
18                 InfoBarSeek.__init__(self)
19                 InfoBarShowHide.__init__(self)
20                 InfoBarAudioSelection.__init__(self)
21                 InfoBarSubtitleSupport.__init__(self)
22                 InfoBarCueSheetSupport.__init__(self)
23                 #TODO FIX THIS HACK
24                 # currently we just want to be able to resume playback (if supported by e2),
25                 # for now we don't care about cutting or jumpmarks or anything like that...
26                 del self["CueSheetActions"]
27
28                 self.session = session
29                 self.service = service
30                 self.infoCallback = infoCallback
31                 self.getNextServiceCB = getNextService
32                 self.getPrevServiceCB = getPrevService
33                 self.stopCB = stopCallback
34                 self.pauseCB = pauseCallback
35                 self.callback = None
36                 self.screen_timeout = 5000
37                 self.nextservice = None
38                 self.is_closing = False
39                 self.restoreService = restoreService
40                 self.oldService = self.session.nav.getCurrentlyPlayingServiceReference()
41
42                 self["actions"] = ActionMap(["OkCancelActions", "InfobarSeekActions", "MediaPlayerActions", "MovieSelectionActions"],
43                 {
44                                 "cancel": self.leavePlayer,
45                                 "stop": self.leavePlayer,
46                                 "playpauseService": self.playpause,
47                                 "previous":  self.playPrev,
48                                 "next": self.playNext,
49                                 "showEventInfo": self.showVideoInfo,
50                         }, -2)
51
52                 self.returning = False
53
54                 self.onShown.append(self.play)
55                 self.onClose.append(self.__onClose)
56
57         def __onClose(self):
58                 if self.stopCB != None:
59                                 self.stopCB()
60                 self.session.nav.stopService()
61                 if self.restoreService:
62                         self.session.nav.playService(self.oldService)
63
64         def createSummary(self):
65                 return SimpleLCDScreen
66
67         def playNext(self):
68                 if self.getNextServiceCB != None:
69                         newservice = self.getNextServiceCB()
70                         debug(self, "playNext", "newservice is %s" %newservice)
71                         if newservice:
72                                 self.playService(newservice)
73                                 return
74
75                 self.leavePlayerConfirmed([True, "quit"])
76
77         def playPrev(self):
78                 if self.getPrevServiceCB != None:
79                         newservice = self.getPrevServiceCB()
80                         debug(self, "playPrev", "newservice is %s" %newservice)
81                         if newservice:
82                                 self.playService(newservice)
83
84                 self.leavePlayerConfirmed([True, "quit"])
85
86         def playAgain(self):
87                 print "playAgain"
88                 self.stopCurrent()
89                 self.play()
90
91         def playService(self, newservice):
92                 self.stopCurrent()
93                 self.service = newservice
94                 self.play()
95
96         def play(self):
97                 text = self.service.getPath()
98                 debug(self, "play", "path=%s" %text)
99                 text = text.split('/')[-1]
100                 debug(self, "play", "text=%s" %text)
101                 self.summaries.setText(text, 3)
102
103                 self.session.nav.playService(self.service)
104                 if self.shown:
105                         self.checkSkipShowHideLock()
106
107         def playpause(self):
108                 self.playpauseService()
109                 if self.pauseCB != None:
110                         self.pauseCB()
111
112         def stopCurrent(self):
113                 print "stopCurrent"
114                 self.session.nav.stopService()
115                 if self.stopCB != None:
116                         self.stopCB()
117
118         def showVideoInfo(self):
119                 if self.infoCallback != None:
120                         self.infoCallback(self.service)
121
122         def handleLeave(self, ask = True, error = False):
123                 self.is_closing = True
124                 if ask:
125                         list = [(_("Yes"), "quit"),
126                                         (_("No, but play video again"), "playAgain")]
127
128                         if self.getNextServiceCB != None:
129                                 list.append( (_("Yes, but play next service"), "playnext") )
130                         if self.getPrevServiceCB != None:
131                                 list.append( (_("Yes, but play previous service"), "playprev") )
132
133                         if error is False:
134                                 self.session.openWithCallback(self.leavePlayerConfirmed, ChoiceBox, title=_("Stop playing this movie?"), list = list)
135                         else:
136                                 self.session.openWithCallback(self.leavePlayerConfirmed, ChoiceBox, title=_("No playable video found! Stop playing this movie?"), list = list)
137                 else:
138                         self.leavePlayerConfirmed([True, "quit"])
139
140         def leavePlayer(self):
141                 self.handleLeave()
142
143         def leavePlayerConfirmed(self, answer):
144                 answer = answer and answer[1]
145                 if answer == "quit":
146                         self.close()
147
148                 elif answer == "playnext":
149                         self.playNext()
150
151                 elif answer == "playprev":
152                         self.playPrev()
153
154                 elif answer == "playAgain":
155                         self.playAgain()
156
157         def doEofInternal(self, playing):
158                 if not self.execing:
159                         return
160                 if not playing :
161                         return
162                 self.playNext()
163
164 # -*- coding: UTF-8 -*-
165
166 from Components.Label import Label
167 from Screens.Screen import Screen
168
169 class SimpleLCDScreen(Screen):
170         skin = (
171         """<screen name="MediaPlayerLCDScreen" position="0,0" size="132,64" id="1">
172                 <widget name="text1" position="4,0" size="132,18" font="Regular;16"/>
173                 <widget name="text2" position="4,19" size="132,14" font="Regular;10"/>
174                 <widget name="text3" position="4,34" size="132,14" font="Regular;10"/>
175                 <widget name="text4" position="4,49" size="132,14" font="Regular;10"/>
176         </screen>""",
177         """<screen name="MediaPlayerLCDScreen" position="0,0" size="96,64" id="2">
178                 <widget name="text1" position="0,0" size="96,18" font="Regular;16"/>
179                 <widget name="text2" position="0,19" size="96,14" font="Regular;10"/>
180                 <widget name="text3" position="0,34" size="96,14" font="Regular;10"/>
181                 <widget name="text4" position="0,49" size="96,14" font="Regular;10"/>
182         </screen>""")
183
184         def __init__(self, session, parent):
185                 Screen.__init__(self, session)
186                 self["text1"] = Label("Playing")
187                 self["text2"] = Label("")
188                 self["text3"] = Label("")
189                 self["text4"] = Label("")
190
191         def setText(self, text, line):
192                 if line == 1:
193                         if len(text) > 15:
194                                 #TODO remove this hack
195                                 if text[-4:-3] == ".":
196                                         text = text[:-4]
197                                 if len(text) > 15:
198                                         text = text[-15:]
199                 else:
200                         if len(text) > 20:
201                                 #TODO remove this hack
202                                 if text[-4:-3] == ".":
203                                         text = text[:-4]
204                                 if len(text) > 20:
205                                         text = text[-20:]
206                 textleer = "    "
207                 text = text + textleer*10
208                 if line == 1:
209                         self["text1"].setText(text)
210                 elif line == 2:
211                         self["text2"].setText(text)
212                 elif line == 3:
213                         self["text3"].setText(text)
214                 elif line == 4:
215                         self["text4"].setText(text)