1 from enigma import eTimer, iPlayableService, eServiceCenter, iServiceInformation, eSize
2 from Screens.Screen import Screen
3 from Screens.MessageBox import MessageBox
4 from Components.ActionMap import NumberActionMap
5 from Components.Label import Label
6 from Components.Input import Input
7 from Components.GUIComponent import *
8 from Components.Pixmap import Pixmap
9 from Components.Label import Label
10 from Components.FileList import FileEntryComponent, FileList
11 from Components.MediaPlayer import PlayList, PlaylistEntryComponent
12 from Plugins.Plugin import PluginDescriptor
13 from Tools.Directories import resolveFilename, SCOPE_MEDIA
14 from Components.ServicePosition import ServicePositionGauge
15 from Screens.ChoiceBox import ChoiceBox
16 from Components.ServiceEventTracker import ServiceEventTracker
17 from Screens.InfoBarGenerics import InfoBarSeek
21 class MediaPlayer(Screen, InfoBarSeek):
22 def __init__(self, session, args = None):
23 Screen.__init__(self, session)
24 self.oldService = self.session.nav.getCurrentlyPlayingServiceReference()
25 self.session.nav.stopService()
27 self.filelist = FileList(resolveFilename(SCOPE_MEDIA), matchingPattern = "^.*\.(mp3|ogg|ts|wav|wave)", useServiceRef = True)
28 self["filelist"] = self.filelist
30 self.playlist = PlayList()
31 self["playlist"] = self.playlist
33 self["PositionGauge"] = ServicePositionGauge(self.session.nav)
35 self["currenttext"] = Label("")
37 self["artisttext"] = Label(_("Artist:"))
38 self["artist"] = Label("")
39 self["titletext"] = Label(_("Title:"))
40 self["title"] = Label("")
41 self["albumtext"] = Label(_("Album:"))
42 self["album"] = Label("")
43 self["yeartext"] = Label(_("Year:"))
44 self["year"] = Label("")
45 self["genretext"] = Label(_("Genre:"))
46 self["genre"] = Label("")
48 #self["text"] = Input("1234", maxSize=True, type=Input.NUMBER)
50 class MoviePlayerActionMap(NumberActionMap):
51 def __init__(self, player, contexts = [ ], actions = { }, prio=0):
52 NumberActionMap.__init__(self, contexts, actions, prio)
55 def action(self, contexts, action):
57 return NumberActionMap.action(self, contexts, action)
59 self["actions"] = MoviePlayerActionMap(self, ["OkCancelActions", "DirectionActions", "NumberActions", "MediaPlayerSeekActions"],
64 "right": self.rightDown,
65 "rightRepeated": self.doNothing,
66 "rightUp": self.rightUp,
67 "left": self.leftDown,
68 "leftRepeated": self.doNothing,
69 "leftUp": self.leftUp,
72 "upRepeated": self.up,
74 "downRepeated": self.down,
76 "play": self.playEntry,
77 "pause": self.pauseEntry,
78 "stop": self.stopEntry,
80 "previous": self.previousEntry,
81 "next": self.nextEntry,
83 "menu": self.showMenu,
85 "1": self.keyNumberGlobal,
86 "2": self.keyNumberGlobal,
87 "3": self.keyNumberGlobal,
88 "4": self.keyNumberGlobal,
89 "5": self.keyNumberGlobal,
90 "6": self.keyNumberGlobal,
91 "7": self.keyNumberGlobal,
92 "8": self.keyNumberGlobal,
93 "9": self.keyNumberGlobal,
94 "0": self.keyNumberGlobal
97 InfoBarSeek.__init__(self)
99 self.__event_tracker = ServiceEventTracker(screen=self, eventmap=
101 # iPlayableService.evSeekableStatusChanged: self.__seekableStatusChanged,
102 # iPlayableService.evStart: self.__serviceStarted,
104 iPlayableService.evEOF: self.__evEOF,
105 # iPlayableService.evSOF: self.__evSOF,
108 self.onClose.append(self.delMPTimer)
109 self.onClose.append(self.__onClose)
111 self.righttimer = False
112 self.rightKeyTimer = eTimer()
113 self.rightKeyTimer.timeout.get().append(self.rightTimerFire)
115 self.lefttimer = False
116 self.leftKeyTimer = eTimer()
117 self.leftKeyTimer.timeout.get().append(self.leftTimerFire)
119 self.infoTimer = eTimer()
120 self.infoTimer.timeout.get().append(self.infoTimerFire)
121 self.infoTimer.start(500)
123 self.currList = "filelist"
131 def checkSkipShowHideLock(self):
132 self.updatedSeekState()
138 self.session.nav.playService(self.oldService)
140 def delMPTimer(self):
141 del self.rightKeyTimer
142 del self.leftKeyTimer
145 def infoTimerFire(self):
146 currPlay = self.session.nav.getCurrentService()
147 if currPlay is not None:
148 self.updateMusicInformation( artist = currPlay.info().getInfoString(iServiceInformation.sArtist),
149 title = currPlay.info().getInfoString(iServiceInformation.sTitle),
150 album = currPlay.info().getInfoString(iServiceInformation.sAlbum),
151 genre = currPlay.info().getInfoString(iServiceInformation.sGenre),
154 self.updateMusicInformation()
156 def updateMusicInformation(self, artist = "", title = "", album = "", year = "", genre = "", clear = False):
157 self.updateSingleMusicInformation("artist", artist, clear)
158 self.updateSingleMusicInformation("title", title, clear)
159 self.updateSingleMusicInformation("album", album, clear)
160 self.updateSingleMusicInformation("year", year, clear)
161 self.updateSingleMusicInformation("genre", genre, clear)
163 def updateSingleMusicInformation(self, name, info, clear):
164 if info != "" or clear:
165 if self[name].getText() != info:
166 self[name].setText(info)
168 def fwdTimerFire(self):
169 self.fwdKeyTimer.stop()
170 self.fwdtimer = False
173 def rwdTimerFire(self):
174 self.rwdKeyTimer.stop()
175 self.rwdtimer = False
179 self.lefttimer = True
180 self.leftKeyTimer.start(1000)
183 self.righttimer = True
184 self.rightKeyTimer.start(1000)
188 self.leftKeyTimer.stop()
189 self.lefttimer = False
190 self[self.currList].pageUp()
194 self.rightKeyTimer.stop()
195 self.righttimer = False
196 self[self.currList].pageDown()
198 def leftTimerFire(self):
199 self.leftKeyTimer.stop()
200 self.lefttimer = False
201 self.switchToFileList()
203 def rightTimerFire(self):
204 self.rightKeyTimer.stop()
205 self.righttimer = False
206 self.switchToPlayList()
208 def switchToFileList(self):
209 self.currList = "filelist"
210 self.filelist.selectionEnabled(1)
211 self.playlist.selectionEnabled(0)
212 self.updateCurrentInfo()
214 def switchToPlayList(self):
215 if len(self.playlist) != 0:
216 self.currList = "playlist"
217 self.filelist.selectionEnabled(0)
218 self.playlist.selectionEnabled(1)
219 self.updateCurrentInfo()
222 self[self.currList].up()
223 self.updateCurrentInfo()
226 self[self.currList].down()
227 self.updateCurrentInfo()
229 def updateCurrentInfo(self):
231 if self.currList == "filelist":
232 if not self.filelist.canDescent():
233 text = self.filelist.getServiceRef().getPath()
234 if self.currList == "playlist":
235 text = self.playlist.getSelection().getPath()
237 self["currenttext"].setText(os.path.basename(text))
240 if self.currList == "filelist":
241 if self.filelist.canDescent():
242 self.filelist.descent()
243 self.updateCurrentInfo()
246 if self.currList == "playlist":
247 selection = self["playlist"].getSelection()
248 self.changeEntry(self.playlist.getSelectionIndex())
250 def keyNumberGlobal(self, number):
255 if self.currList == "filelist":
256 menu.append((_("switch to playlist"), "playlist"))
257 if self.filelist.canDescent():
258 menu.append((_("add directory to playlist"), "copydir"))
260 menu.append((_("add file to playlist"), "copy"))
262 menu.append((_("switch to filelist"), "filelist"))
263 menu.append((_("delete"), "delete"))
264 menu.append((_("clear playlist"), "clear"))
265 menu.append((_("hide player"), "hide"));
266 self.session.openWithCallback(self.menuCallback, ChoiceBox, title="", list=menu)
268 def menuCallback(self, choice):
272 if choice[1] == "copydir":
273 self.copyDirectory(self.filelist.getSelection()[0])
274 elif choice[1] == "copy":
276 elif choice[1] == "playlist":
277 self.switchToPlayList()
278 elif choice[1] == "filelist":
279 self.switchToFileList()
280 elif choice[1] == "delete":
282 elif choice[1] == "clear":
284 self.playlist.clear()
285 self.switchToFileList()
286 elif choice[1] == "hide":
289 def copyDirectory(self, directory):
290 filelist = FileList(directory, useServiceRef = True, isTop = True)
292 for x in filelist.getFileList():
293 if x[0][1] == True: #isDir
294 self.copyDirectory(x[0][0])
296 self.playlist.addFile(x[0][0])
297 self.playlist.updateList()
300 self.playlist.addFile(self.filelist.getServiceRef())
301 self.playlist.updateList()
302 if len(self.playlist) == 1:
306 next = self.playlist.getCurrentIndex() + 1
307 if next < len(self.playlist):
308 self.changeEntry(next)
310 def previousEntry(self):
311 next = self.playlist.getCurrentIndex() - 1
313 self.changeEntry(next)
315 def deleteEntry(self):
316 self.playlist.deleteFile(self.playlist.getSelectionIndex())
317 self.playlist.updateList()
318 if len(self.playlist) == 0:
319 self.switchToFileList()
321 def changeEntry(self, index):
322 self.playlist.setCurrentPlaying(index)
326 if len(self.playlist.getServiceRefList()):
327 currref = self.playlist.getServiceRefList()[self.playlist.getCurrentIndex()]
328 if self.session.nav.getCurrentlyPlayingServiceReference() is None or currref != self.session.nav.getCurrentlyPlayingServiceReference():
329 self.session.nav.playService(self.playlist.getServiceRefList()[self.playlist.getCurrentIndex()])
330 info = eServiceCenter.getInstance().info(currref)
331 description = info and info.getInfoString(currref, iServiceInformation.sDescription) or ""
332 self["title"].setText(description)
333 self.unPauseService()
335 def updatedSeekState(self):
336 if self.seekstate == self.SEEK_STATE_PAUSE:
337 self.playlist.pauseFile()
338 elif self.seekstate == self.SEEK_STATE_PLAY:
339 self.playlist.playFile()
340 elif self.seekstate in ( self.SEEK_STATE_FF_2X,
341 self.SEEK_STATE_FF_4X,
342 self.SEEK_STATE_FF_8X,
343 self.SEEK_STATE_FF_32X,
344 self.SEEK_STATE_FF_64X,
345 self.SEEK_STATE_FF_128X):
346 self.playlist.forwardFile()
347 elif self.seekstate in ( self.SEEK_STATE_BACK_16X,
348 self.SEEK_STATE_BACK_32X,
349 self.SEEK_STATE_BACK_64X,
350 self.SEEK_STATE_BACK_128X,):
351 self.playlist.rewindFile()
353 def pauseEntry(self):
357 self.playlist.stopFile()
358 self.session.nav.playService(None)