(ralfk) media player
[enigma2.git] / lib / python / Screens / MediaPlayer.py
1 import os
2 import time
3 from enigma import eTimer, iPlayableService, eServiceCenter, iServiceInformation, eSize
4 from Screens.Screen import Screen
5 from Screens.MessageBox import MessageBox
6 from Screens.InputBox import InputBox
7 from Components.ActionMap import NumberActionMap, ActionMap, HelpableActionMap
8 from Components.Label import Label
9 from Components.Input import Input
10 from Components.Pixmap import Pixmap
11 from Components.Label import Label
12 from Components.FileList import FileEntryComponent, FileList
13 from Components.MediaPlayer import PlayList, PlaylistEntryComponent
14 from Plugins.Plugin import PluginDescriptor
15 from Tools.Directories import resolveFilename, SCOPE_MEDIA, SCOPE_CONFIG, SCOPE_PLAYLIST, SCOPE_SKIN_IMAGE
16 from Components.ServicePosition import ServicePositionGauge
17 from Components.ServiceEventTracker import ServiceEventTracker
18 from Components.Playlist import PlaylistIOInternal, PlaylistIOM3U, PlaylistIOPLS
19 from Screens.InfoBarGenerics import InfoBarSeek, InfoBarAudioSelection, InfoBarCueSheetSupport, InfoBarNotifications
20 from ServiceReference import ServiceReference
21 from Screens.ChoiceBox import ChoiceBox
22 from Screens.HelpMenu import HelpableScreen
23 from bisect import insort
24 import random
25
26 class MyPlayList(PlayList):
27         def __init__(self):
28                 PlayList.__init__(self)
29
30         def PlayListShuffle(self):
31                 random.shuffle(self.list)
32                 self.l.setList(self.list)
33                 self.currPlaying = -1
34                 self.oldCurrPlaying = -1
35
36 class MediaPlayer(Screen, InfoBarSeek, InfoBarAudioSelection, InfoBarCueSheetSupport, InfoBarNotifications, HelpableScreen):
37         ALLOW_SUSPEND = True
38         ENABLE_RESUME_SUPPORT = True
39
40         def __init__(self, session, args = None):
41                 Screen.__init__(self, session)
42                 InfoBarAudioSelection.__init__(self)
43                 InfoBarCueSheetSupport.__init__(self, actionmap = "MediaPlayerCueSheetActions")
44                 InfoBarNotifications.__init__(self)
45                 HelpableScreen.__init__(self)
46                 self.summary = None
47                 self.oldService = self.session.nav.getCurrentlyPlayingServiceReference()
48                 self.session.nav.stopService()
49
50                 self.playlistparsers = {}
51                 self.addPlaylistParser(PlaylistIOM3U, "m3u")
52                 self.addPlaylistParser(PlaylistIOPLS, "pls")
53                 self.addPlaylistParser(PlaylistIOInternal, "e2pls")
54
55                 # 'None' is magic to start at the list of mountpoints
56                 self.filelist = FileList(None, matchingPattern = "(?i)^.*\.(mp3|ogg|ts|wav|wave|m3u|pls|e2pls|mpg|vob)", useServiceRef = True)
57                 self["filelist"] = self.filelist
58
59                 self.playlist = MyPlayList()
60                 #self.playlist = PlayList()
61                 self.is_closing = False
62                 self.delname = ""
63                 self["playlist"] = self.playlist
64
65                 self["PositionGauge"] = ServicePositionGauge(self.session.nav)
66
67                 self["currenttext"] = Label("")
68
69                 self["artisttext"] = Label(_("Artist:"))
70                 self["artist"] = Label("")
71                 self["titletext"] = Label(_("Title:"))
72                 self["title"] = Label("")
73                 self["albumtext"] = Label(_("Album:"))
74                 self["album"] = Label("")
75                 self["yeartext"] = Label(_("Year:"))
76                 self["year"] = Label("")
77                 self["genretext"] = Label(_("Genre:"))
78                 self["genre"] = Label("")
79                 self["coverArt"] = Pixmap()
80
81                 self.seek_target = None
82
83                 class MoviePlayerActionMap(NumberActionMap):
84                         def __init__(self, player, contexts = [ ], actions = { }, prio=0):
85                                 NumberActionMap.__init__(self, contexts, actions, prio)
86                                 self.player = player
87
88                         def action(self, contexts, action):
89                                 self.player.show()
90                                 return NumberActionMap.action(self, contexts, action)
91
92
93                 self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions", 
94                         {
95                                 "ok": (self.ok, _("add file to playlist")),
96                                 "cancel": (self.exit, _("exit mediaplayer")),
97                         }, -2)
98
99                 self["MediaPlayerActions"] = HelpableActionMap(self, "MediaPlayerActions", 
100                         {
101                                 "play": (self.playEntry, _("play entry")),
102                                 "pause": (self.pauseEntry, _("pause")),
103                                 "stop": (self.stopEntry, _("stop entry")),
104                                 "previous": (self.previousEntry, _("play previous playlist entry")),
105                                 "next": (self.nextEntry, _("play next playlist entry")),
106                                 "menu": (self.showMenu, _("menu")),
107                                 "skipListbegin": (self.skip_listbegin, _("jump to listbegin")),
108                                 "skipListend": (self.skip_listend, _("jump to listend")),
109                                 "prevBouquet": (self.switchToPlayList, _("switch to playlist")),
110                                 "nextBouquet": (self.switchToFileList, _("switch to filelist")),
111                                 "delete": (self.deletePlaylistEntry, _("delete playlist entry")),
112                                 "shift_stop": (self.clear_playlist, _("clear playlist")),
113                                 "shift_record": (self.playlist.PlayListShuffle, _("shuffle playlist")),
114                         }, -2)
115
116                 self["InfobarEPGActions"] = HelpableActionMap(self, "InfobarEPGActions", 
117                         {
118                                 "showEventInfo": (self.showEventInformation, _("show event details")),
119                         })
120
121                 self["actions"] = MoviePlayerActionMap(self, ["DirectionActions"], 
122                 {
123                         "right": self.rightDown,
124                         "rightRepeated": self.doNothing,
125                         "rightUp": self.rightUp,
126                         "left": self.leftDown,
127                         "leftRepeated": self.doNothing,
128                         "leftUp": self.leftUp,
129
130                         "up": self.up,
131                         "upRepeated": self.up,
132                         "upUp": self.doNothing,
133                         "down": self.down,
134                         "downRepeated": self.down,
135                         "downUp": self.doNothing,
136                 }, -2)
137
138                 InfoBarSeek.__init__(self, actionmap = "MediaPlayerSeekActions")
139
140                 self.__event_tracker = ServiceEventTracker(screen=self, eventmap=
141                         {
142                                 #iPlayableService.evStart: self.__serviceStarted,
143                                 #iPlayableService.evSeekableStatusChanged: InfoBarSeek.__seekableStatusChanged,
144
145                                 iPlayableService.evEOF: self.__evEOF,
146                         })
147
148                 self.onClose.append(self.delMPTimer)
149                 self.onClose.append(self.__onClose)
150
151                 self.righttimer = False
152                 self.rightKeyTimer = eTimer()
153                 self.rightKeyTimer.timeout.get().append(self.rightTimerFire)
154
155                 self.lefttimer = False
156                 self.leftKeyTimer = eTimer()
157                 self.leftKeyTimer.timeout.get().append(self.leftTimerFire)
158
159                 self.infoTimer = eTimer()
160                 self.infoTimer.timeout.get().append(self.infoTimerFire)
161                 self.infoTimer.start(500)
162
163                 self.currList = "filelist"
164
165                 self.coverArtFileName = ""
166
167                 self.playlistIOInternal = PlaylistIOInternal()
168                 list = self.playlistIOInternal.open(resolveFilename(SCOPE_CONFIG, "playlist.e2pls"))
169                 if list:
170                         for x in list:
171                                 self.playlist.addFile(x.ref)
172                         self.playlist.updateList()
173
174         def doNothing(self):
175                 pass
176
177         def createSummary(self):
178                 return MediaPlayerLCDScreen
179
180         def exit(self):
181                 self.session.openWithCallback(self.exitCB, MessageBox, _("Do you really want to exit?"), timeout=5)
182
183         def exitCB(self, answer):
184                 if answer == True:
185                         self.playlistIOInternal.clear()
186                         for x in self.playlist.list:
187                                 self.playlistIOInternal.addService(ServiceReference(x[0]))
188                         self.playlistIOInternal.save(resolveFilename(SCOPE_CONFIG, "playlist.e2pls"))
189                         self.close()
190
191         def checkSkipShowHideLock(self):
192                 self.updatedSeekState()
193
194         def __evEOF(self):
195                 self.nextEntry()
196
197         def __onClose(self):
198                 self.session.nav.playService(self.oldService)
199
200         def delMPTimer(self):
201                 del self.rightKeyTimer
202                 del self.leftKeyTimer
203                 del self.infoTimer
204
205         def infoTimerFire(self):
206                 currPlay = self.session.nav.getCurrentService()
207                 if currPlay is not None:
208                         stitle = currPlay.info().getInfoString(iServiceInformation.sTitle)
209                         if stitle == "":
210                                 stitle = currPlay.info().getName().split('/')[-1]
211
212                         self.updateMusicInformation( artist = currPlay.info().getInfoString(iServiceInformation.sArtist),
213                                                                                  title = stitle,
214                                                                                  album = currPlay.info().getInfoString(iServiceInformation.sAlbum),
215                                                                                  genre = currPlay.info().getInfoString(iServiceInformation.sGenre),
216                                                                                  clear = True)
217                         self.updateCoverArtPixmap( currPlay.info().getName() )
218                 else:
219                         self.updateMusicInformation()
220                         self.updateCoverArtPixmap( "" )
221
222         def updateMusicInformation(self, artist = "", title = "", album = "", year = "", genre = "", clear = False):
223                 self.updateSingleMusicInformation("artist", artist, clear)
224                 self.updateSingleMusicInformation("title", title, clear)
225                 self.updateSingleMusicInformation("album", album, clear)
226                 self.updateSingleMusicInformation("year", year, clear)
227                 self.updateSingleMusicInformation("genre", genre, clear)
228
229         def updateSingleMusicInformation(self, name, info, clear):
230                 if info != "" or clear:
231                         if self[name].getText() != info:
232                                 self[name].setText(info)
233
234         def updateCoverArtPixmap(self, currentServiceName):
235                 filename = currentServiceName
236                 # The "getName" usually adds something like "MP3 File:" infront of filename
237                 # Get rid of this...by finding the first "/"
238                 # FIXME: this should be fixed in the servicemp3.cpp handler
239                 filename = filename[filename.find("/"):]
240                 path = os.path.dirname(filename)
241                 pngname = path + "/" + "folder.png"
242                 if not os.path.exists(pngname):
243                         pngname = resolveFilename(SCOPE_SKIN_IMAGE, "no_coverArt.png")
244                 if self.coverArtFileName != pngname:
245                         self.coverArtFileName = pngname
246                         self["coverArt"].instance.setPixmapFromFile(self.coverArtFileName)
247
248         def leftDown(self):
249                 self.lefttimer = True
250                 self.leftKeyTimer.start(1000)
251
252         def rightDown(self):
253                 self.righttimer = True
254                 self.rightKeyTimer.start(1000)
255
256         def leftUp(self):
257                 if self.lefttimer:
258                         self.leftKeyTimer.stop()
259                         self.lefttimer = False
260                         self[self.currList].pageUp()
261                         self.updateCurrentInfo()
262
263         def rightUp(self):
264                 if self.righttimer:
265                         self.rightKeyTimer.stop()
266                         self.righttimer = False
267                         self[self.currList].pageDown()
268                         self.updateCurrentInfo()
269
270         def leftTimerFire(self):
271                 self.leftKeyTimer.stop()
272                 self.lefttimer = False
273                 self.switchToFileList()
274
275         def rightTimerFire(self):
276                 self.rightKeyTimer.stop()
277                 self.righttimer = False
278                 self.switchToPlayList()
279
280         def switchToFileList(self):
281                 self.currList = "filelist"
282                 self.filelist.selectionEnabled(1)
283                 self.playlist.selectionEnabled(0)
284                 self.updateCurrentInfo()
285
286         def switchToPlayList(self):
287                 if len(self.playlist) != 0:
288                         self.currList = "playlist"
289                         self.filelist.selectionEnabled(0)
290                         self.playlist.selectionEnabled(1)
291                         self.updateCurrentInfo()
292
293         def up(self):
294                 self[self.currList].up()
295                 self.updateCurrentInfo()
296
297         def down(self):
298                 self[self.currList].down()
299                 self.updateCurrentInfo()
300
301         def showAfterSeek(self):
302                 self.show()
303
304         def showAfterCuesheetOperation(self):
305                 self.show()
306
307         def hideAfterResume(self):
308                 self.hide()
309
310         # FIXME: maybe this code can be optimized 
311         def updateCurrentInfo(self):
312                 text = ""
313                 if self.currList == "filelist":
314                         idx = self.filelist.getSelectionIndex()
315                         r = self.filelist.list[idx]
316                         text = r[1][7]
317                         if r[0][1] == True:
318                                 if len(text) < 2:
319                                         text += " "
320                                 if text[:2] != "..":
321                                         text = "/" + text
322                         self.summaries.setText(text,1)
323
324                         idx += 1
325                         if idx < len(self.filelist.list):
326                                 r = self.filelist.list[idx]
327                                 text = r[1][7]
328                                 if r[0][1] == True:
329                                         text = "/" + text
330                                 self.summaries.setText(text,3)
331                         else:
332                                 self.summaries.setText(" ",3)
333
334                         idx += 1
335                         if idx < len(self.filelist.list):
336                                 r = self.filelist.list[idx]
337                                 text = r[1][7]
338                                 if r[0][1] == True:
339                                         text = "/" + text
340                                 self.summaries.setText(text,4)
341                         else:
342                                 self.summaries.setText(" ",4)
343
344                         text = ""
345                         if not self.filelist.canDescent():
346                                 r = self.filelist.getServiceRef()
347                                 if r is None:
348                                         return
349                                 text = r.getPath()
350                                 self["currenttext"].setText(os.path.basename(text))
351
352                 if self.currList == "playlist":
353                         t = self.playlist.getSelection()
354                         if t is None:
355                                 return
356                         #display current selected entry on LCD
357                         text = t.getPath()
358                         text = text.split('/')[-1]
359                         self.summaries.setText(text,1)
360                         self["currenttext"].setText(text)
361                         idx = self.playlist.getSelectionIndex()
362                         idx += 1
363                         if idx < len(self.playlist):
364                                 currref = self.playlist.getServiceRefList()[idx]
365                                 text = currref.getPath()
366                                 text = text.split('/')[-1]
367                                 self.summaries.setText(text,3)
368                         else:
369                                 self.summaries.setText(" ",3)
370
371                         idx += 1
372                         if idx < len(self.playlist):
373                                 currref = self.playlist.getServiceRefList()[idx]
374                                 text = currref.getPath()
375                                 text = text.split('/')[-1]
376                                 self.summaries.setText(text,4)
377                         else:
378                                 self.summaries.setText(" ",4)
379
380         def ok(self):
381                 if self.currList == "filelist":
382                         if self.filelist.canDescent():
383                                 self.filelist.descent()
384                                 self.updateCurrentInfo()
385                         else:
386                                 self.copyFile()
387
388                 if self.currList == "playlist":
389                         selection = self["playlist"].getSelection()
390                         self.changeEntry(self.playlist.getSelectionIndex())
391
392         def showMenu(self):
393                 menu = []
394                 if self.currList == "filelist":
395                         if self.filelist.canDescent():
396                                 menu.append((_("add directory to playlist"), "copydir"))
397                         else:
398                                 menu.append((_("add files to playlist"), "copyfiles"))
399                         menu.append((_("switch to playlist"), "playlist"))
400                 else:
401                         menu.append((_("switch to filelist"), "filelist"))
402
403                         menu.append((_("shuffle playlist"), "shuffle"))
404
405                         menu.append((_("delete"), "delete"))
406                         menu.append((_("clear playlist"), "clear"))
407                 menu.append((_("hide player"), "hide"));
408                 menu.append((_("save playlist"), "saveplaylist"));
409                 menu.append((_("load playlist"), "loadplaylist"));
410                 menu.append((_("delete saved playlist"), "deleteplaylist"));
411                 self.session.openWithCallback(self.menuCallback, ChoiceBox, title="", list=menu)
412
413         def menuCallback(self, choice):
414                 if choice is None:
415                         return
416
417                 if choice[1] == "copydir":
418                         self.copyDirectory(self.filelist.getSelection()[0])
419                 elif choice[1] == "copyfiles":
420                         self.stopEntry()
421                         self.playlist.clear()
422                         self.copyDirectory(os.path.dirname(self.filelist.getSelection()[0].getPath()) + "/", recursive = False)
423                         self.playServiceRefEntry(self.filelist.getServiceRef())
424                 elif choice[1] == "playlist":
425                         self.switchToPlayList()
426                 elif choice[1] == "filelist":
427                         self.switchToFileList()
428                 elif choice[1] == "delete":
429                         if self.playlist.getSelectionIndex() == self.playlist.getCurrentIndex():
430                                 self.stopEntry()
431                         self.deleteEntry()
432                 elif choice[1] == "clear":
433                         self.stopEntry()
434                         self.playlist.clear()
435                         self.switchToFileList()
436                 elif choice[1] == "hide":
437                         self.hide()
438                 elif choice[1] == "saveplaylist":
439                         self.save_playlist()
440                 elif choice[1] == "loadplaylist":
441                         self.load_playlist()
442                 elif choice[1] == "deleteplaylist":
443                         self.delete_saved_playlist()
444                 elif choice[1] == "shuffle":
445                         self.playlist.PlayListShuffle()
446
447
448         def showEventInformation(self):
449                 from Screens.EventView import EventViewSimple
450                 from ServiceReference import ServiceReference
451                 evt = self[self.currList].getCurrentEvent()
452                 if evt:
453                         self.session.open(EventViewSimple, evt, ServiceReference(self.getCurrent()))
454
455         # also works on filelist (?)
456         def getCurrent(self):
457                 return self["playlist"].getCurrent()
458
459         def deletePlaylistEntry(self):
460                 if self.currList == "playlist":
461                         if self.playlist.getSelectionIndex() == self.playlist.getCurrentIndex():
462                                 self.stopEntry()
463                         self.deleteEntry()
464
465         def skip_listbegin(self):
466                 if self.currList == "filelist":
467                         self.filelist.moveToIndex(0)
468                 else:
469                         self.playlist.moveToIndex(0)
470                 self.updateCurrentInfo()
471
472         def skip_listend(self):
473                 if self.currList == "filelist":
474                         idx = len(self.filelist.list)
475                         self.filelist.moveToIndex(idx - 1)
476                 else:
477                         self.playlist.moveToIndex(len(self.playlist)-1)
478                 self.updateCurrentInfo()
479
480         def save_playlist(self):
481                 self.session.openWithCallback(self.save_playlist2,InputBox, title=_("Please enter filename (empty = use current date)"),windowTitle = _("Save Playlist"))
482
483         def save_playlist2(self, name):
484                 if name is not None:
485                         name = name.strip()
486                         if name == "":
487                                 name = time.strftime("%y%m%d_%H%M%S")
488                         name += ".e2pls"
489                         self.playlistIOInternal.clear()
490                         for x in self.playlist.list:
491                                 self.playlistIOInternal.addService(ServiceReference(x[0]))
492                         self.playlistIOInternal.save(resolveFilename(SCOPE_PLAYLIST) + name)
493
494         def load_playlist(self):
495                 listpath = []
496                 playlistdir = resolveFilename(SCOPE_PLAYLIST)
497                 try:
498                         for i in os.listdir(playlistdir):
499                                 listpath.append((i,playlistdir + i))
500                 except IOError,e:
501                         print "Error while scanning subdirs ",e
502                 self.session.openWithCallback(self.PlaylistSelected, ChoiceBox, title=_("Please select a playlist..."), list = listpath)
503
504         def PlaylistSelected(self,path):
505                 if path is not None:
506                         self.clear_playlist()
507                         self.playlistIOInternal = PlaylistIOInternal()
508                         list = self.playlistIOInternal.open(path[1])
509                         if list:
510                                 for x in list:
511                                         self.playlist.addFile(x.ref)
512                                 self.playlist.updateList()
513
514         def delete_saved_playlist(self):
515                 listpath = []
516                 playlistdir = resolveFilename(SCOPE_PLAYLIST)
517                 try:
518                         for i in os.listdir(playlistdir):
519                                 listpath.append((i,playlistdir + i))
520                 except IOError,e:
521                         print "Error while scanning subdirs ",e
522                 self.session.openWithCallback(self.DeletePlaylistSelected, ChoiceBox, title=_("Please select a playlist to delete..."), list = listpath)
523
524         def DeletePlaylistSelected(self,path):
525                 if path is not None:
526                         self.delname = path[1]
527                         self.session.openWithCallback(self.deleteConfirmed, MessageBox, _("Do you really want to delete %s?") % (path[1]))
528
529         def deleteConfirmed(self, confirmed):
530                 if confirmed:
531                         os.remove(self.delname)
532
533         def clear_playlist(self):
534                 self.stopEntry()
535                 self.playlist.clear()
536                 self.switchToFileList()
537
538         def copyDirectory(self, directory, recursive = True):
539                 print "copyDirectory", directory
540                 filelist = FileList(directory, useServiceRef = True, isTop = True)
541
542                 for x in filelist.getFileList():
543                         if x[0][1] == True: #isDir
544                                 if recursive:
545                                         self.copyDirectory(x[0][0])
546                         else:
547                                 self.playlist.addFile(x[0][0])
548                 self.playlist.updateList()
549
550         def copyFile(self):
551                 if self.filelist.getServiceRef().type == 4098: # playlist
552                         ServiceRef = self.filelist.getServiceRef()
553                         extension = ServiceRef.getPath()[ServiceRef.getPath().rfind('.') + 1:]
554                         print "extension:", extension
555                         if self.playlistparsers.has_key(extension):
556                                 playlist = self.playlistparsers[extension]()
557                                 list = playlist.open(ServiceRef.getPath())
558                                 for x in list:
559                                         self.playlist.addFile(x.ref)
560                 else:
561                         self.playlist.addFile(self.filelist.getServiceRef())
562                         self.playlist.updateList()
563                         if len(self.playlist) == 1:
564                                 self.changeEntry(0)
565
566         def addPlaylistParser(self, parser, extension):
567                 self.playlistparsers[extension] = parser
568
569         def nextEntry(self):
570                 next = self.playlist.getCurrentIndex() + 1
571                 if next < len(self.playlist):
572                         self.changeEntry(next)
573
574         def previousEntry(self):
575                 next = self.playlist.getCurrentIndex() - 1
576                 if next >= 0:
577                         self.changeEntry(next)
578
579         def deleteEntry(self):
580                 self.playlist.deleteFile(self.playlist.getSelectionIndex())
581                 self.playlist.updateList()
582                 if len(self.playlist) == 0:
583                         self.switchToFileList()
584
585         def changeEntry(self, index):
586                 self.playlist.setCurrentPlaying(index)
587                 self.playEntry()
588
589         def playServiceRefEntry(self, serviceref):
590                 serviceRefList = self.playlist.getServiceRefList()
591                 for count in range(len(serviceRefList)):
592                         if serviceRefList[count] == serviceref:
593                                 self.changeEntry(count)
594                                 break
595
596         def playEntry(self):
597                 if len(self.playlist.getServiceRefList()):
598                         currref = self.playlist.getServiceRefList()[self.playlist.getCurrentIndex()]
599                         if self.session.nav.getCurrentlyPlayingServiceReference() is None or currref != self.session.nav.getCurrentlyPlayingServiceReference():
600                                 self.session.nav.playService(self.playlist.getServiceRefList()[self.playlist.getCurrentIndex()])
601                                 info = eServiceCenter.getInstance().info(currref)
602                                 description = info and info.getInfoString(currref, iServiceInformation.sDescription) or ""
603                                 self["title"].setText(description)
604                                 # display just playing musik on LCD
605                                 idx = self.playlist.getCurrentIndex()
606                                 currref = self.playlist.getServiceRefList()[idx]
607                                 text = currref.getPath()
608                                 text = text.split('/')[-1]
609                                 text = ">"+text
610                                 ext = text[-3:].lower()
611
612                                 # FIXME: the information if the service contains video (and we should hide our window) should com from the service instead 
613                                 if ext not in ["mp3", "wav", "ogg"]:
614                                         self.hide()
615                                 self.summaries.setText(text,1)
616
617                                 # get the next two entries
618                                 idx += 1
619                                 if idx < len(self.playlist):
620                                         currref = self.playlist.getServiceRefList()[idx]
621                                         text = currref.getPath()
622                                         text = text.split('/')[-1]
623                                         self.summaries.setText(text,3)
624                                 else:
625                                         self.summaries.setText(" ",3)
626
627                                 idx += 1
628                                 if idx < len(self.playlist):
629                                         currref = self.playlist.getServiceRefList()[idx]
630                                         text = currref.getPath()
631                                         text = text.split('/')[-1]
632                                         self.summaries.setText(text,4)
633                                 else:
634                                         self.summaries.setText(" ",4)
635                         else:
636                                 idx = self.playlist.getCurrentIndex()
637                                 currref = self.playlist.getServiceRefList()[idx]
638                                 text = currref.getPath()
639                                 ext = text[-3:].lower()
640                                 if ext not in ["mp3", "wav", "ogg"]:
641                                         self.hide()
642                         self.unPauseService()
643
644         def updatedSeekState(self):
645                 if self.seekstate == self.SEEK_STATE_PAUSE:
646                         self.playlist.pauseFile()
647                 elif self.seekstate == self.SEEK_STATE_PLAY:
648                         self.playlist.playFile()
649                 elif self.seekstate in ( self.SEEK_STATE_FF_2X,
650                                                                  self.SEEK_STATE_FF_4X,
651                                                                  self.SEEK_STATE_FF_8X,
652                                                                  self.SEEK_STATE_FF_32X,
653                                                                  self.SEEK_STATE_FF_64X,
654                                                                  self.SEEK_STATE_FF_128X):
655                         self.playlist.forwardFile()
656                 elif self.seekstate in ( self.SEEK_STATE_BACK_16X,
657                                                                  self.SEEK_STATE_BACK_32X,
658                                                                  self.SEEK_STATE_BACK_64X,
659                                                                  self.SEEK_STATE_BACK_128X,):
660                         self.playlist.rewindFile()
661
662         def pauseEntry(self):
663                 self.pauseService()
664                 self.show()
665
666         def stopEntry(self):
667                 self.playlist.stopFile()
668                 self.session.nav.playService(None)
669                 self.updateMusicInformation(clear=True)
670                 self.show()
671
672         def unPauseService(self):
673                 self.setSeekState(self.SEEK_STATE_PLAY)
674
675
676 class MediaPlayerLCDScreen(Screen):
677         skin = """
678         <screen position="0,0" size="132,64" title="LCD Text">
679                 <widget name="text1" position="4,0" size="132,35" font="Regular;16"/>
680                 <widget name="text3" position="4,36" size="132,14" font="Regular;10"/>
681                 <widget name="text4" position="4,49" size="132,14" font="Regular;10"/>
682         </screen>"""
683
684         def __init__(self, session, parent):
685                 Screen.__init__(self, session)
686                 self["text1"] = Label("Mediaplayer")
687                 self["text3"] = Label("")
688                 self["text4"] = Label("")
689
690         def setText(self, text, line):
691                 print "lcd set text:", text, line
692                 if len(text) > 10:
693                         if text[-4:] == ".mp3":
694                                 text = text[:-4]
695                 textleer = "    "
696                 text = text + textleer*10
697                 if line == 1:
698                         self["text1"].setText(text)
699                 elif line == 3:
700                         self["text3"].setText(text)
701                 elif line == 4:
702                         self["text4"].setText(text)