movie player configuration options, by Anders Holst
[enigma2.git] / lib / python / Plugins / Extensions / MediaPlayer / plugin.py
index 7efd33e..fa7f164 100644 (file)
@@ -30,6 +30,18 @@ class MyPlayList(PlayList):
                self.currPlaying = -1
                self.oldCurrPlaying = -1
 
                self.currPlaying = -1
                self.oldCurrPlaying = -1
 
+class MediaPixmap(Pixmap):
+       def applySkin(self, desktop):
+               self.default_pixmap = None
+               if self.skinAttributes is not None:
+                       for (attrib, value) in self.skinAttributes:
+                               if attrib == "pixmap":
+                                       self.default_pixmap = value
+                                       break
+               if self.default_pixmap is None:
+                       self.default_pixmap = resolveFilename(SCOPE_SKIN_IMAGE, "no_coverArt.png")
+               return Pixmap.applySkin(self, desktop)
+
 class MediaPlayer(Screen, InfoBarSeek, InfoBarAudioSelection, InfoBarCueSheetSupport, InfoBarNotifications, HelpableScreen):
        ALLOW_SUSPEND = True
        ENABLE_RESUME_SUPPORT = True
 class MediaPlayer(Screen, InfoBarSeek, InfoBarAudioSelection, InfoBarCueSheetSupport, InfoBarNotifications, HelpableScreen):
        ALLOW_SUSPEND = True
        ENABLE_RESUME_SUPPORT = True
@@ -73,7 +85,7 @@ class MediaPlayer(Screen, InfoBarSeek, InfoBarAudioSelection, InfoBarCueSheetSup
                self["year"] = Label("")
                self["genretext"] = Label(_("Genre:"))
                self["genre"] = Label("")
                self["year"] = Label("")
                self["genretext"] = Label(_("Genre:"))
                self["genre"] = Label("")
-               self["coverArt"] = Pixmap()
+               self["coverArt"] = MediaPixmap()
 
                self.seek_target = None
 
 
                self.seek_target = None
 
@@ -95,11 +107,11 @@ class MediaPlayer(Screen, InfoBarSeek, InfoBarAudioSelection, InfoBarCueSheetSup
 
                self["MediaPlayerActions"] = HelpableActionMap(self, "MediaPlayerActions", 
                        {
 
                self["MediaPlayerActions"] = HelpableActionMap(self, "MediaPlayerActions", 
                        {
-                               "play": (self.playEntry, _("play entry")),
+                               "play": (self.xplayEntry, _("play entry")),
                                "pause": (self.pauseEntry, _("pause")),
                                "stop": (self.stopEntry, _("stop entry")),
                                "pause": (self.pauseEntry, _("pause")),
                                "stop": (self.stopEntry, _("stop entry")),
-                               "previous": (self.previousEntry, _("play previous playlist entry")),
-                               "next": (self.nextEntry, _("play next playlist entry")),
+                               "previous": (self.previousMarkOrEntry, _("play from previous mark or playlist entry")),
+                               "next": (self.nextMarkOrEntry, _("play from next mark or playlist entry")),
                                "menu": (self.showMenu, _("menu")),
                                "skipListbegin": (self.skip_listbegin, _("jump to listbegin")),
                                "skipListend": (self.skip_listend, _("jump to listend")),
                                "menu": (self.showMenu, _("menu")),
                                "skipListbegin": (self.skip_listbegin, _("jump to listbegin")),
                                "skipListend": (self.skip_listend, _("jump to listend")),
@@ -134,28 +146,16 @@ class MediaPlayer(Screen, InfoBarSeek, InfoBarAudioSelection, InfoBarCueSheetSup
 
                InfoBarSeek.__init__(self, actionmap = "MediaPlayerSeekActions")
 
 
                InfoBarSeek.__init__(self, actionmap = "MediaPlayerSeekActions")
 
-               self.__event_tracker = ServiceEventTracker(screen=self, eventmap=
-                       {
-                               #iPlayableService.evStart: self.__serviceStarted,
-                               #iPlayableService.evSeekableStatusChanged: InfoBarSeek.__seekableStatusChanged,
-
-                               iPlayableService.evEOF: self.__evEOF,
-                       })
-
                self.onClose.append(self.delMPTimer)
                self.onClose.append(self.__onClose)
 
                self.righttimer = False
                self.rightKeyTimer = eTimer()
                self.onClose.append(self.delMPTimer)
                self.onClose.append(self.__onClose)
 
                self.righttimer = False
                self.rightKeyTimer = eTimer()
-               self.rightKeyTimer.timeout.get().append(self.rightTimerFire)
+               self.rightKeyTimer.callback.append(self.rightTimerFire)
 
                self.lefttimer = False
                self.leftKeyTimer = eTimer()
 
                self.lefttimer = False
                self.leftKeyTimer = eTimer()
-               self.leftKeyTimer.timeout.get().append(self.leftTimerFire)
-
-               self.infoTimer = eTimer()
-               self.infoTimer.timeout.get().append(self.infoTimerFire)
-               self.infoTimer.start(500)
+               self.leftKeyTimer.callback.append(self.leftTimerFire)
 
                self.currList = "filelist"
 
 
                self.currList = "filelist"
 
@@ -188,8 +188,11 @@ class MediaPlayer(Screen, InfoBarSeek, InfoBarAudioSelection, InfoBarCueSheetSup
        def checkSkipShowHideLock(self):
                self.updatedSeekState()
 
        def checkSkipShowHideLock(self):
                self.updatedSeekState()
 
-       def __evEOF(self):
-               self.nextEntry()
+       def doEofInternal(self, playing):
+               if playing:
+                       self.nextEntry()
+               else:
+                       self.show()
 
        def __onClose(self):
                self.session.nav.playService(self.oldService)
 
        def __onClose(self):
                self.session.nav.playService(self.oldService)
@@ -197,9 +200,8 @@ class MediaPlayer(Screen, InfoBarSeek, InfoBarAudioSelection, InfoBarCueSheetSup
        def delMPTimer(self):
                del self.rightKeyTimer
                del self.leftKeyTimer
        def delMPTimer(self):
                del self.rightKeyTimer
                del self.leftKeyTimer
-               del self.infoTimer
 
 
-       def infoTimerFire(self):
+       def readTitleInformation(self):
                currPlay = self.session.nav.getCurrentService()
                if currPlay is not None:
                        stitle = currPlay.info().getInfoString(iServiceInformation.sTitle)
                currPlay = self.session.nav.getCurrentService()
                if currPlay is not None:
                        stitle = currPlay.info().getInfoString(iServiceInformation.sTitle)
@@ -211,10 +213,8 @@ class MediaPlayer(Screen, InfoBarSeek, InfoBarAudioSelection, InfoBarCueSheetSup
                                                                                 album = currPlay.info().getInfoString(iServiceInformation.sAlbum),
                                                                                 genre = currPlay.info().getInfoString(iServiceInformation.sGenre),
                                                                                 clear = True)
                                                                                 album = currPlay.info().getInfoString(iServiceInformation.sAlbum),
                                                                                 genre = currPlay.info().getInfoString(iServiceInformation.sGenre),
                                                                                 clear = True)
-                       self.updateCoverArtPixmap( currPlay.info().getName() )
                else:
                        self.updateMusicInformation()
                else:
                        self.updateMusicInformation()
-                       self.updateCoverArtPixmap( "" )
 
        def updateMusicInformation(self, artist = "", title = "", album = "", year = "", genre = "", clear = False):
                self.updateSingleMusicInformation("artist", artist, clear)
 
        def updateMusicInformation(self, artist = "", title = "", album = "", year = "", genre = "", clear = False):
                self.updateSingleMusicInformation("artist", artist, clear)
@@ -228,16 +228,13 @@ class MediaPlayer(Screen, InfoBarSeek, InfoBarAudioSelection, InfoBarCueSheetSup
                        if self[name].getText() != info:
                                self[name].setText(info)
 
                        if self[name].getText() != info:
                                self[name].setText(info)
 
-       def updateCoverArtPixmap(self, currentServiceName):
-               filename = currentServiceName
-               # The "getName" usually adds something like "MP3 File:" infront of filename
-               # Get rid of this...by finding the first "/"
-               # FIXME: this should be fixed in the servicemp3.cpp handler
-               filename = filename[filename.find("/"):]
-               path = os_path.dirname(filename)
-               pngname = path + "/" + "folder.png"
+       def updateCoverArtPixmap(self, path):
+               while not path.endswith("/"):
+                       path = path[:-1]
+               pngname = path + "folder.png"
+               
                if not os_path.exists(pngname):
                if not os_path.exists(pngname):
-                       pngname = resolveFilename(SCOPE_SKIN_IMAGE, "no_coverArt.png")
+                       pngname = self["coverArt"].default_pixmap
                if self.coverArtFileName != pngname:
                        self.coverArtFileName = pngname
                        self["coverArt"].instance.setPixmapFromFile(self.coverArtFileName)
                if self.coverArtFileName != pngname:
                        self.coverArtFileName = pngname
                        self["coverArt"].instance.setPixmapFromFile(self.coverArtFileName)
@@ -568,10 +565,19 @@ class MediaPlayer(Screen, InfoBarSeek, InfoBarAudioSelection, InfoBarCueSheetSup
                if next < len(self.playlist):
                        self.changeEntry(next)
 
                if next < len(self.playlist):
                        self.changeEntry(next)
 
-       def previousEntry(self):
-               next = self.playlist.getCurrentIndex() - 1
-               if next >= 0:
-                       self.changeEntry(next)
+       def nextMarkOrEntry(self):
+               if not self.jumpPreviousNextMark(lambda x: x):
+                       next = self.playlist.getCurrentIndex() + 1
+                       if next < len(self.playlist):
+                               self.changeEntry(next)
+                       else:
+                               self.doSeek(-1)
+
+       def previousMarkOrEntry(self):
+               if not self.jumpPreviousNextMark(lambda x: -x-5*90000, start=True):
+                       next = self.playlist.getCurrentIndex() - 1
+                       if next >= 0:
+                               self.changeEntry(next)
 
        def deleteEntry(self):
                self.playlist.deleteFile(self.playlist.getSelectionIndex())
 
        def deleteEntry(self):
                self.playlist.deleteFile(self.playlist.getSelectionIndex())
@@ -589,9 +595,27 @@ class MediaPlayer(Screen, InfoBarSeek, InfoBarAudioSelection, InfoBarCueSheetSup
                        if serviceRefList[count] == serviceref:
                                self.changeEntry(count)
                                break
                        if serviceRefList[count] == serviceref:
                                self.changeEntry(count)
                                break
-
+                       
+       def xplayEntry(self):
+               if self.currList == "playlist":
+                       self.playEntry()
+               else:
+                       self.stopEntry()
+                       self.playlist.clear()
+                       sel = self.filelist.getSelection()
+                       if sel:
+                               if sel[1]: # can descent
+                                       # add directory to playlist
+                                       self.copyDirectory(sel[0])
+                               else:
+                                       # add files to playlist
+                                       self.copyDirectory(os_path.dirname(sel[0].getPath()) + "/", recursive = False)
+                       if len(self.playlist) > 0:
+                               self.changeEntry(0)
+       
        def playEntry(self):
                if len(self.playlist.getServiceRefList()):
        def playEntry(self):
                if len(self.playlist.getServiceRefList()):
+                       needsInfoUpdate = False
                        currref = self.playlist.getServiceRefList()[self.playlist.getCurrentIndex()]
                        if self.session.nav.getCurrentlyPlayingServiceReference() is None or currref != self.session.nav.getCurrentlyPlayingServiceReference():
                                self.session.nav.playService(self.playlist.getServiceRefList()[self.playlist.getCurrentIndex()])
                        currref = self.playlist.getServiceRefList()[self.playlist.getCurrentIndex()]
                        if self.session.nav.getCurrentlyPlayingServiceReference() is None or currref != self.session.nav.getCurrentlyPlayingServiceReference():
                                self.session.nav.playService(self.playlist.getServiceRefList()[self.playlist.getCurrentIndex()])
@@ -609,6 +633,8 @@ class MediaPlayer(Screen, InfoBarSeek, InfoBarAudioSelection, InfoBarCueSheetSup
                                # FIXME: the information if the service contains video (and we should hide our window) should com from the service instead 
                                if ext not in ["mp3", "wav", "ogg"]:
                                        self.hide()
                                # FIXME: the information if the service contains video (and we should hide our window) should com from the service instead 
                                if ext not in ["mp3", "wav", "ogg"]:
                                        self.hide()
+                               else:
+                                       needsInfoUpdate = True
                                self.summaries.setText(text,1)
 
                                # get the next two entries
                                self.summaries.setText(text,1)
 
                                # get the next two entries
@@ -636,28 +662,26 @@ class MediaPlayer(Screen, InfoBarSeek, InfoBarAudioSelection, InfoBarCueSheetSup
                                ext = text[-3:].lower()
                                if ext not in ["mp3", "wav", "ogg"]:
                                        self.hide()
                                ext = text[-3:].lower()
                                if ext not in ["mp3", "wav", "ogg"]:
                                        self.hide()
+                               else:
+                                       needsInfoUpdate = True
+
                        self.unPauseService()
                        self.unPauseService()
+                       if needsInfoUpdate == True:
+                               self.updateCoverArtPixmap(currref.getPath())
+                       else:
+                               pngname = self["coverArt"].default_pixmap
+                               self.coverArtFileName = pngname
+                               self["coverArt"].instance.setPixmapFromFile(self.coverArtFileName)
+                       self.readTitleInformation()
 
        def updatedSeekState(self):
                if self.seekstate == self.SEEK_STATE_PAUSE:
                        self.playlist.pauseFile()
                elif self.seekstate == self.SEEK_STATE_PLAY:
                        self.playlist.playFile()
 
        def updatedSeekState(self):
                if self.seekstate == self.SEEK_STATE_PAUSE:
                        self.playlist.pauseFile()
                elif self.seekstate == self.SEEK_STATE_PLAY:
                        self.playlist.playFile()
-               elif self.seekstate in ( self.SEEK_STATE_FF_2X,
-                                                                self.SEEK_STATE_FF_4X,
-                                                                self.SEEK_STATE_FF_8X,
-                                                                self.SEEK_STATE_FF_16X,
-                                                                self.SEEK_STATE_FF_32X,
-                                                                self.SEEK_STATE_FF_48X,
-                                                                self.SEEK_STATE_FF_64X,
-                                                                self.SEEK_STATE_FF_128X):
+               elif self.isStateForward(self.seekstate):
                        self.playlist.forwardFile()
                        self.playlist.forwardFile()
-               elif self.seekstate in ( self.SEEK_STATE_BACK_8X,
-                                                                self.SEEK_STATE_BACK_16X,
-                                                                self.SEEK_STATE_BACK_32X,
-                                                                self.SEEK_STATE_BACK_48X,
-                                                                self.SEEK_STATE_BACK_64X,
-                                                                self.SEEK_STATE_BACK_128X):
+               elif self.isStateBackward(self.seekstate):
                        self.playlist.rewindFile()
 
        def pauseEntry(self):
                        self.playlist.rewindFile()
 
        def pauseEntry(self):
@@ -707,7 +731,7 @@ def main(session, **kwargs):
 
 def menu(menuid, **kwargs):
        if menuid == "mainmenu":
 
 def menu(menuid, **kwargs):
        if menuid == "mainmenu":
-               return [(_("Media player"), main, "media_player")]
+               return [(_("Media player"), main, "media_player", 45)]
        return []
 
 def filescan_open(list, session, **kwargs):
        return []
 
 def filescan_open(list, session, **kwargs):