fix getBouquetList
[enigma2.git] / lib / python / Screens / MediaPlayer.py
index 622d218625815daf640c85f473efd9ef240864ff..1411b427d4d1ca19fc0a14a722d274431f8c152f 100644 (file)
@@ -34,14 +34,15 @@ class MediaPlayer(Screen, InfoBarSeek):
                self.addPlaylistParser(PlaylistIOPLS, "pls")
                self.addPlaylistParser(PlaylistIOInternal, "e2pls")
 
-               self.filelist = FileList(resolveFilename(SCOPE_MEDIA), matchingPattern = "(?i)^.*\.(mp3|ogg|ts|wav|wave|m3u|pls|e2pls|mpg|vob)", useServiceRef = True)
+               # 'None' is magic to start at the list of mountpoints
+               self.filelist = FileList(None, matchingPattern = "(?i)^.*\.(mp3|ogg|ts|wav|wave|m3u|pls|e2pls|mpg|vob)", useServiceRef = True)
                self["filelist"] = self.filelist
 
                self.playlist = PlayList()
                self["playlist"] = self.playlist
 
                self["PositionGauge"] = ServicePositionGauge(self.session.nav)
-
+               
                self["currenttext"] = Label("")
 
                self["artisttext"] = Label(_("Artist:"))
@@ -55,7 +56,9 @@ class MediaPlayer(Screen, InfoBarSeek):
                self["genretext"] = Label(_("Genre:"))
                self["genre"] = Label("")
                self["coverArt"] = Pixmap()
-
+               
+               self.seek_target = None
+               
                #self["text"] = Input("1234", maxSize=True, type=Input.NUMBER)
 
                class MoviePlayerActionMap(NumberActionMap):
@@ -269,9 +272,15 @@ class MediaPlayer(Screen, InfoBarSeek):
                text = ""
                if self.currList == "filelist":
                        if not self.filelist.canDescent():
-                               text = self.filelist.getServiceRef().getPath()
+                               r = self.filelist.getServiceRef()
+                               if r is None:
+                                       return
+                               text = r.getPath()
                if self.currList == "playlist":
-                       text = self.playlist.getSelection().getPath()
+                       t = self.playlist.getSelection()
+                       if t is None:
+                               return
+                       text = t.getPath()
 
                self["currenttext"].setText(os.path.basename(text))
 
@@ -281,13 +290,52 @@ class MediaPlayer(Screen, InfoBarSeek):
                                self.filelist.descent()
                                self.updateCurrentInfo()
                        else:
-                               self.copyFile()
+                               self.stopEntry()
+                               self.playlist.clear()
+                               self.copyDirectory(os.path.dirname(self.filelist.getSelection()[0].getPath()) + "/", recursive = False)
+                               self.playServiceRefEntry(self.filelist.getServiceRef())
+                               
                if self.currList == "playlist":
                        selection = self["playlist"].getSelection()
                        self.changeEntry(self.playlist.getSelectionIndex())
 
        def keyNumberGlobal(self, number):
-               pass
+               if number == 5: # enable seeking
+                       if self.seek_target is None:
+                               (len, pos) = self["PositionGauge"].get()
+                               
+                               if self.isSeekable() and len != 0:
+                                       self.seek_target = pos
+                       else:
+                               self.seekAbsolute(self.seek_target)
+                               self.seek_target = None
+               elif number == 2: # abort
+                       self.seek_target = None
+               elif (number == 4 or number == 6) and self.seek_target is not None:
+                       (len, pos) = self["PositionGauge"].get()
+                       
+                       if number == 4:
+                               self.seek_target -= len / 10
+                       else:
+                               self.seek_target += len / 10
+                       
+                       if self.seek_target > len * 9 / 10:
+                               self.seek_target = len * 9 / 10
+                       
+                       if self.seek_target < 0:
+                               self.seek_target = 0
+
+               print "seek target is now", self.seek_target
+               
+               self.updateSeek()
+       
+       def updateSeek(self):
+               if self.seek_target is None:
+                       self["PositionGauge"].seek_pointer = False
+               else:
+                       self["PositionGauge"].seek_pointer = True
+                       self["PositionGauge"].seek_pointer_position = self.seek_target
+
 
        def showMenu(self):
                menu = []
@@ -327,12 +375,14 @@ class MediaPlayer(Screen, InfoBarSeek):
                elif choice[1] == "hide":
                        self.hide()
 
-       def copyDirectory(self, directory):
+       def copyDirectory(self, directory, recursive = True):
+               print "copyDirectory", directory
                filelist = FileList(directory, useServiceRef = True, isTop = True)
 
                for x in filelist.getFileList():
                        if x[0][1] == True: #isDir
-                               self.copyDirectory(x[0][0])
+                               if recursive:
+                                       self.copyDirectory(x[0][0])
                        else:
                                self.playlist.addFile(x[0][0])
                self.playlist.updateList()
@@ -391,6 +441,13 @@ class MediaPlayer(Screen, InfoBarSeek):
                self.playlist.setCurrentPlaying(index)
                self.playEntry()
 
+       def playServiceRefEntry(self, serviceref):
+               serviceRefList = self.playlist.getServiceRefList()
+               for count in range(len(serviceRefList)):
+                       if serviceRefList[count] == serviceref:
+                               self.changeEntry(count)
+                               break
+
        def playEntry(self):
                if len(self.playlist.getServiceRefList()):
                        currref = self.playlist.getServiceRefList()[self.playlist.getCurrentIndex()]