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 self["actions"] = NumberActionMap(["OkCancelActions", "DirectionActions", "NumberActions", "MediaPlayerSeekActions"],
55 "right": self.rightDown,
56 "rightRepeated": self.doNothing,
57 "rightUp": self.rightUp,
58 "left": self.leftDown,
59 "leftRepeated": self.doNothing,
60 "leftUp": self.leftUp,
63 "upRepeated": self.up,
65 "downRepeated": self.down,
67 "play": self.playEntry,
68 "pause": self.pauseEntry,
69 "stop": self.stopEntry,
71 "previous": self.previousEntry,
72 "next": self.nextEntry,
74 "menu": self.showMenu,
76 "1": self.keyNumberGlobal,
77 "2": self.keyNumberGlobal,
78 "3": self.keyNumberGlobal,
79 "4": self.keyNumberGlobal,
80 "5": self.keyNumberGlobal,
81 "6": self.keyNumberGlobal,
82 "7": self.keyNumberGlobal,
83 "8": self.keyNumberGlobal,
84 "9": self.keyNumberGlobal,
85 "0": self.keyNumberGlobal
88 InfoBarSeek.__init__(self)
90 self.__event_tracker = ServiceEventTracker(screen=self, eventmap=
92 # iPlayableService.evSeekableStatusChanged: self.__seekableStatusChanged,
93 # iPlayableService.evStart: self.__serviceStarted,
95 iPlayableService.evEOF: self.__evEOF,
96 # iPlayableService.evSOF: self.__evSOF,
99 self.onClose.append(self.delMPTimer)
100 self.onClose.append(self.__onClose)
102 self.righttimer = False
103 self.rightKeyTimer = eTimer()
104 self.rightKeyTimer.timeout.get().append(self.rightTimerFire)
106 self.lefttimer = False
107 self.leftKeyTimer = eTimer()
108 self.leftKeyTimer.timeout.get().append(self.leftTimerFire)
110 self.infoTimer = eTimer()
111 self.infoTimer.timeout.get().append(self.infoTimerFire)
112 self.infoTimer.start(500)
114 self.currList = "filelist"
122 def checkSkipShowHideLock(self):
123 self.updatedSeekState()
129 self.session.nav.playService(self.oldService)
131 def delMPTimer(self):
132 del self.rightKeyTimer
133 del self.leftKeyTimer
136 def infoTimerFire(self):
137 currPlay = self.session.nav.getCurrentService()
138 if currPlay is not None:
139 self.updateMusicInformation( artist = currPlay.info().getInfoString(iServiceInformation.sArtist),
140 title = currPlay.info().getInfoString(iServiceInformation.sTitle),
141 album = currPlay.info().getInfoString(iServiceInformation.sAlbum),
142 genre = currPlay.info().getInfoString(iServiceInformation.sGenre),
145 self.updateMusicInformation()
147 def updateMusicInformation(self, artist = "", title = "", album = "", year = "", genre = "", clear = False):
148 self.updateSingleMusicInformation("artist", artist, clear)
149 self.updateSingleMusicInformation("title", title, clear)
150 self.updateSingleMusicInformation("album", album, clear)
151 self.updateSingleMusicInformation("year", year, clear)
152 self.updateSingleMusicInformation("genre", genre, clear)
154 def updateSingleMusicInformation(self, name, info, clear):
155 if info != "" or clear:
156 if self[name].getText() != info:
157 self[name].setText(info)
159 def fwdTimerFire(self):
160 self.fwdKeyTimer.stop()
161 self.fwdtimer = False
164 def rwdTimerFire(self):
165 self.rwdKeyTimer.stop()
166 self.rwdtimer = False
170 self.lefttimer = True
171 self.leftKeyTimer.start(1000)
174 self.righttimer = True
175 self.rightKeyTimer.start(1000)
179 self.leftKeyTimer.stop()
180 self.lefttimer = False
181 self[self.currList].pageUp()
185 self.rightKeyTimer.stop()
186 self.righttimer = False
187 self[self.currList].pageDown()
189 def leftTimerFire(self):
190 self.leftKeyTimer.stop()
191 self.lefttimer = False
192 self.switchToFileList()
194 def rightTimerFire(self):
195 self.rightKeyTimer.stop()
196 self.righttimer = False
197 self.switchToPlayList()
199 def switchToFileList(self):
200 self.currList = "filelist"
201 self.filelist.selectionEnabled(1)
202 self.playlist.selectionEnabled(0)
203 self.updateCurrentInfo()
205 def switchToPlayList(self):
206 if len(self.playlist) != 0:
207 self.currList = "playlist"
208 self.filelist.selectionEnabled(0)
209 self.playlist.selectionEnabled(1)
210 self.updateCurrentInfo()
213 self[self.currList].up()
214 self.updateCurrentInfo()
217 self[self.currList].down()
218 self.updateCurrentInfo()
220 def updateCurrentInfo(self):
222 if self.currList == "filelist":
223 if not self.filelist.canDescent():
224 text = self.filelist.getServiceRef().getPath()
225 if self.currList == "playlist":
226 text = self.playlist.getSelection().getPath()
228 self["currenttext"].setText(os.path.basename(text))
231 if self.currList == "filelist":
232 if self.filelist.canDescent():
233 self.filelist.descent()
234 self.updateCurrentInfo()
237 if self.currList == "playlist":
238 selection = self["playlist"].getSelection()
239 self.changeEntry(self.playlist.getSelectionIndex())
241 def keyNumberGlobal(self, number):
246 if self.currList == "filelist":
247 menu.append((_("switch to playlist"), "playlist"))
248 if self.filelist.canDescent():
249 menu.append((_("add directory to playlist"), "copydir"))
251 menu.append((_("add file to playlist"), "copy"))
253 menu.append((_("switch to filelist"), "filelist"))
254 menu.append((_("delete"), "delete"))
255 menu.append((_("clear playlist"), "clear"))
256 self.session.openWithCallback(self.menuCallback, ChoiceBox, title="", list=menu)
258 def menuCallback(self, choice):
262 if choice[1] == "copydir":
263 self.copyDirectory(self.filelist.getSelection()[0])
264 elif choice[1] == "copy":
266 elif choice[1] == "playlist":
267 self.switchToPlayList()
268 elif choice[1] == "filelist":
269 self.switchToFileList()
270 elif choice[1] == "delete":
272 elif choice[1] == "clear":
274 self.playlist.clear()
275 self.switchToFileList()
277 def copyDirectory(self, directory):
278 filelist = FileList(directory, useServiceRef = True, isTop = True)
280 for x in filelist.getFileList():
281 if x[0][1] == True: #isDir
282 self.copyDirectory(x[0][0])
284 self.playlist.addFile(x[0][0])
285 self.playlist.updateList()
288 self.playlist.addFile(self.filelist.getServiceRef())
289 self.playlist.updateList()
290 if len(self.playlist) == 1:
294 next = self.playlist.getCurrentIndex() + 1
295 if next < len(self.playlist):
296 self.changeEntry(next)
298 def previousEntry(self):
299 next = self.playlist.getCurrentIndex() - 1
301 self.changeEntry(next)
303 def deleteEntry(self):
304 self.playlist.deleteFile(self.playlist.getSelectionIndex())
305 self.playlist.updateList()
306 if len(self.playlist) == 0:
307 self.switchToFileList()
309 def changeEntry(self, index):
310 self.playlist.setCurrentPlaying(index)
314 if len(self.playlist.getServiceRefList()):
315 currref = self.playlist.getServiceRefList()[self.playlist.getCurrentIndex()]
316 if self.session.nav.getCurrentlyPlayingServiceReference() is None or currref != self.session.nav.getCurrentlyPlayingServiceReference():
317 self.session.nav.playService(self.playlist.getServiceRefList()[self.playlist.getCurrentIndex()])
318 info = eServiceCenter.getInstance().info(currref)
319 description = info.getInfoString(currref, iServiceInformation.sDescription)
320 self["title"].setText(description)
321 self.unPauseService()
323 def updatedSeekState(self):
324 if self.seekstate == self.SEEK_STATE_PAUSE:
325 self.playlist.pauseFile()
326 elif self.seekstate == self.SEEK_STATE_PLAY:
327 self.playlist.playFile()
328 elif self.seekstate in ( self.SEEK_STATE_FF_2X,
329 self.SEEK_STATE_FF_4X,
330 self.SEEK_STATE_FF_8X,
331 self.SEEK_STATE_FF_32X,
332 self.SEEK_STATE_FF_64X,
333 self.SEEK_STATE_FF_128X):
334 self.playlist.forwardFile()
335 elif self.seekstate in ( self.SEEK_STATE_BACK_16X,
336 self.SEEK_STATE_BACK_32X,
337 self.SEEK_STATE_BACK_64X,
338 self.SEEK_STATE_BACK_128X,):
339 self.playlist.rewindFile()
341 def pauseEntry(self):
345 self.playlist.stopFile()
346 self.session.nav.playService(None)