from Components.ActionMap import NumberActionMap
from Components.Label import Label
from Components.Input import Input
-from Components.GUIComponent import *
from Components.Pixmap import Pixmap
from Components.Label import Label
from Components.FileList import FileEntryComponent, FileList
from Components.MediaPlayer import PlayList, PlaylistEntryComponent
from Plugins.Plugin import PluginDescriptor
-from Tools.Directories import resolveFilename, SCOPE_MEDIA, SCOPE_CONFIG
+from Tools.Directories import resolveFilename, SCOPE_MEDIA, SCOPE_CONFIG, SCOPE_SKIN_IMAGE
from Components.ServicePosition import ServicePositionGauge
from Screens.ChoiceBox import ChoiceBox
from Components.ServiceEventTracker import ServiceEventTracker
import os
class MediaPlayer(Screen, InfoBarSeek):
+ ALLOW_SUSPEND = True
+
def __init__(self, session, args = None):
Screen.__init__(self, session)
self.oldService = self.session.nav.getCurrentlyPlayingServiceReference()
self.addPlaylistParser(PlaylistIOPLS, "pls")
self.addPlaylistParser(PlaylistIOInternal, "e2pls")
- self.filelist = FileList(resolveFilename(SCOPE_MEDIA), matchingPattern = "^.*\.(mp3|ogg|ts|wav|wave|m3u|pls|e2pls)", 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:"))
self["artist"] = Label("")
self["titletext"] = Label(_("Title:"))
self["year"] = Label("")
self["genretext"] = Label(_("Genre:"))
self["genre"] = Label("")
+ self["coverArt"] = Pixmap()
+
+ self.seek_target = None
#self["text"] = Input("1234", maxSize=True, type=Input.NUMBER)
{
"ok": self.ok,
"cancel": self.exit,
-
+
"right": self.rightDown,
"rightRepeated": self.doNothing,
"rightUp": self.rightUp,
"left": self.leftDown,
"leftRepeated": self.doNothing,
"leftUp": self.leftUp,
-
+
"up": self.up,
"upRepeated": self.up,
"down": self.down,
"downRepeated": self.down,
-
+
"play": self.playEntry,
"pause": self.pauseEntry,
"stop": self.stopEntry,
-
+
"previous": self.previousEntry,
"next": self.nextEntry,
-
+
"menu": self.showMenu,
-
- "1": self.keyNumberGlobal,
- "2": self.keyNumberGlobal,
- "3": self.keyNumberGlobal,
- "4": self.keyNumberGlobal,
- "5": self.keyNumberGlobal,
- "6": self.keyNumberGlobal,
- "7": self.keyNumberGlobal,
- "8": self.keyNumberGlobal,
- "9": self.keyNumberGlobal,
- "0": self.keyNumberGlobal
- }, -2)
+
+ "1": self.keyNumberGlobal,
+ "2": self.keyNumberGlobal,
+ "3": self.keyNumberGlobal,
+ "4": self.keyNumberGlobal,
+ "5": self.keyNumberGlobal,
+ "6": self.keyNumberGlobal,
+ "7": self.keyNumberGlobal,
+ "8": self.keyNumberGlobal,
+ "9": self.keyNumberGlobal,
+ "0": self.keyNumberGlobal
+ }, -2)
InfoBarSeek.__init__(self)
self.onClose.append(self.delMPTimer)
self.onClose.append(self.__onClose)
-
+
self.righttimer = False
self.rightKeyTimer = eTimer()
self.rightKeyTimer.timeout.get().append(self.rightTimerFire)
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.currList = "filelist"
-
+
+ self.coverArtFileName = ""
+
self.playlistIOInternal = PlaylistIOInternal()
list = self.playlistIOInternal.open(resolveFilename(SCOPE_CONFIG, "playlist.e2pls"))
if list:
for x in list:
self.playlist.addFile(x.ref)
- self.playlist.updateList()
-
+ self.playlist.updateList()
+
def doNothing(self):
pass
-
+
def exit(self):
self.playlistIOInternal.clear()
for x in self.playlist.list:
self.playlistIOInternal.addService(ServiceReference(x[0]))
self.playlistIOInternal.save(resolveFilename(SCOPE_CONFIG, "playlist.e2pls"))
self.close()
-
+
def checkSkipShowHideLock(self):
self.updatedSeekState()
-
+
def __evEOF(self):
self.nextEntry()
-
+
def __onClose(self):
self.session.nav.playService(self.oldService)
-
+
def delMPTimer(self):
del self.rightKeyTimer
del self.leftKeyTimer
del self.infoTimer
-
+
def infoTimerFire(self):
currPlay = self.session.nav.getCurrentService()
if currPlay is not None:
album = currPlay.info().getInfoString(iServiceInformation.sAlbum),
genre = currPlay.info().getInfoString(iServiceInformation.sGenre),
clear = True)
+ self.updateCoverArtPixmap( currPlay.info().getName() )
else:
self.updateMusicInformation()
-
+ self.updateCoverArtPixmap( "" )
+
def updateMusicInformation(self, artist = "", title = "", album = "", year = "", genre = "", clear = False):
self.updateSingleMusicInformation("artist", artist, clear)
self.updateSingleMusicInformation("title", title, clear)
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 "/"
+ filename = filename[filename.find("/"):]
+ path = os.path.dirname(filename)
+ pngname = path + "/" + "folder.png"
+ if not os.path.exists(pngname):
+ pngname = resolveFilename(SCOPE_SKIN_IMAGE, "no_coverArt.png")
+ if self.coverArtFileName != pngname:
+ self.coverArtFileName = pngname
+ self["coverArt"].instance.setPixmapFromFile(self.coverArtFileName)
+
def fwdTimerFire(self):
self.fwdKeyTimer.stop()
self.fwdtimer = False
self.nextEntry()
-
+
def rwdTimerFire(self):
self.rwdKeyTimer.stop()
self.rwdtimer = False
self.previousEntry()
-
+
def leftDown(self):
self.lefttimer = True
self.leftKeyTimer.start(1000)
def rightDown(self):
self.righttimer = True
self.rightKeyTimer.start(1000)
-
+
def leftUp(self):
if self.lefttimer:
self.leftKeyTimer.stop()
self.lefttimer = False
self[self.currList].pageUp()
-
+
def rightUp(self):
if self.righttimer:
self.rightKeyTimer.stop()
self.righttimer = False
self[self.currList].pageDown()
-
+
def leftTimerFire(self):
self.leftKeyTimer.stop()
self.lefttimer = False
self.switchToFileList()
-
+
def rightTimerFire(self):
self.rightKeyTimer.stop()
self.righttimer = False
self.switchToPlayList()
-
+
def switchToFileList(self):
self.currList = "filelist"
self.filelist.selectionEnabled(1)
self.playlist.selectionEnabled(0)
self.updateCurrentInfo()
-
+
def switchToPlayList(self):
if len(self.playlist) != 0:
self.currList = "playlist"
self.filelist.selectionEnabled(0)
self.playlist.selectionEnabled(1)
self.updateCurrentInfo()
-
+
def up(self):
self[self.currList].up()
self.updateCurrentInfo()
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))
-
+
def ok(self):
if self.currList == "filelist":
if self.filelist.canDescent():
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 = []
if self.currList == "filelist":
menu.append((_("clear playlist"), "clear"))
menu.append((_("hide player"), "hide"));
self.session.openWithCallback(self.menuCallback, ChoiceBox, title="", list=menu)
-
+
def menuCallback(self, choice):
if choice is None:
return
-
+
if choice[1] == "copydir":
self.copyDirectory(self.filelist.getSelection()[0])
elif choice[1] == "copy":
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()
-
+
ADDPLAYLIST = 0
REPLACEPLAYLIST = 1
-
+
def copyFile(self):
if self.filelist.getServiceRef().type == 4098: # playlist
list = []
list = playlist.open(answer[1][1].getPath())
for x in list:
self.playlist.addFile(x.ref)
-
+
def nextEntry(self):
next = self.playlist.getCurrentIndex() + 1
if next < len(self.playlist):
self.changeEntry(next)
-
+
def previousEntry(self):
next = self.playlist.getCurrentIndex() - 1
if next >= 0:
self.changeEntry(next)
-
+
def deleteEntry(self):
self.playlist.deleteFile(self.playlist.getSelectionIndex())
self.playlist.updateList()
if len(self.playlist) == 0:
self.switchToFileList()
-
+
def changeEntry(self, index):
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()]
description = info and info.getInfoString(currref, iServiceInformation.sDescription) or ""
self["title"].setText(description)
self.unPauseService()
-
+
def updatedSeekState(self):
if self.seekstate == self.SEEK_STATE_PAUSE:
self.playlist.pauseFile()
self.SEEK_STATE_BACK_64X,
self.SEEK_STATE_BACK_128X,):
self.playlist.rewindFile()
-
+
def pauseEntry(self):
self.pauseService()
-
+
def stopEntry(self):
self.playlist.stopFile()
self.session.nav.playService(None)
def unPauseService(self):
self.setSeekState(self.SEEK_STATE_PLAY)
-
-
-