Fix Mediaplayer crash for WAV playback and add basic Audio CD support (needs kernel...
[enigma2.git] / lib / python / Plugins / Extensions / MediaPlayer / plugin.py
index fa7f164303ca295b0592c09bd6b23c1e66652b4b..0613ed0a5d229c12946d864deb070e076c22a326 100644 (file)
@@ -1,6 +1,6 @@
 from os import path as os_path, remove as os_remove, listdir as os_listdir
 from time import strftime
 from os import path as os_path, remove as os_remove, listdir as os_listdir
 from time import strftime
-from enigma import eTimer, iPlayableService, eServiceCenter, iServiceInformation
+from enigma import eTimer, eServiceCenter, iServiceInformation
 from Screens.Screen import Screen
 from Screens.MessageBox import MessageBox
 from Screens.InputBox import InputBox
 from Screens.Screen import Screen
 from Screens.MessageBox import MessageBox
 from Screens.InputBox import InputBox
@@ -12,7 +12,7 @@ from Components.FileList import FileList
 from Components.MediaPlayer import PlayList
 from Tools.Directories import resolveFilename, SCOPE_CONFIG, SCOPE_PLAYLIST, SCOPE_SKIN_IMAGE
 from Components.ServicePosition import ServicePositionGauge
 from Components.MediaPlayer import PlayList
 from Tools.Directories import resolveFilename, SCOPE_CONFIG, SCOPE_PLAYLIST, SCOPE_SKIN_IMAGE
 from Components.ServicePosition import ServicePositionGauge
-from Components.ServiceEventTracker import ServiceEventTracker
+from Components.ServiceEventTracker import InfoBarBase
 from Components.Playlist import PlaylistIOInternal, PlaylistIOM3U, PlaylistIOPLS
 from Screens.InfoBarGenerics import InfoBarSeek, InfoBarAudioSelection, InfoBarCueSheetSupport, InfoBarNotifications
 from ServiceReference import ServiceReference
 from Components.Playlist import PlaylistIOInternal, PlaylistIOM3U, PlaylistIOPLS
 from Screens.InfoBarGenerics import InfoBarSeek, InfoBarAudioSelection, InfoBarCueSheetSupport, InfoBarNotifications
 from ServiceReference import ServiceReference
@@ -31,7 +31,7 @@ class MyPlayList(PlayList):
                self.oldCurrPlaying = -1
 
 class MediaPixmap(Pixmap):
                self.oldCurrPlaying = -1
 
 class MediaPixmap(Pixmap):
-       def applySkin(self, desktop):
+       def applySkin(self, desktop, screen):
                self.default_pixmap = None
                if self.skinAttributes is not None:
                        for (attrib, value) in self.skinAttributes:
                self.default_pixmap = None
                if self.skinAttributes is not None:
                        for (attrib, value) in self.skinAttributes:
@@ -39,10 +39,10 @@ class MediaPixmap(Pixmap):
                                        self.default_pixmap = value
                                        break
                if self.default_pixmap is None:
                                        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)
+                       self.default_pixmap = resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/no_coverArt.png")
+               return Pixmap.applySkin(self, desktop, screen)
 
 
-class MediaPlayer(Screen, InfoBarSeek, InfoBarAudioSelection, InfoBarCueSheetSupport, InfoBarNotifications, HelpableScreen):
+class MediaPlayer(Screen, InfoBarBase, InfoBarSeek, InfoBarAudioSelection, InfoBarCueSheetSupport, InfoBarNotifications, HelpableScreen):
        ALLOW_SUSPEND = True
        ENABLE_RESUME_SUPPORT = True
 
        ALLOW_SUSPEND = True
        ENABLE_RESUME_SUPPORT = True
 
@@ -51,6 +51,7 @@ class MediaPlayer(Screen, InfoBarSeek, InfoBarAudioSelection, InfoBarCueSheetSup
                InfoBarAudioSelection.__init__(self)
                InfoBarCueSheetSupport.__init__(self, actionmap = "MediaPlayerCueSheetActions")
                InfoBarNotifications.__init__(self)
                InfoBarAudioSelection.__init__(self)
                InfoBarCueSheetSupport.__init__(self, actionmap = "MediaPlayerCueSheetActions")
                InfoBarNotifications.__init__(self)
+               InfoBarBase.__init__(self)
                HelpableScreen.__init__(self)
                self.summary = None
                self.oldService = self.session.nav.getCurrentlyPlayingServiceReference()
                HelpableScreen.__init__(self)
                self.summary = None
                self.oldService = self.session.nav.getCurrentlyPlayingServiceReference()
@@ -62,7 +63,7 @@ class MediaPlayer(Screen, InfoBarSeek, InfoBarAudioSelection, InfoBarCueSheetSup
                self.addPlaylistParser(PlaylistIOInternal, "e2pls")
 
                # 'None' is magic to start at the list of mountpoints
                self.addPlaylistParser(PlaylistIOInternal, "e2pls")
 
                # '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 = FileList(None, matchingPattern = "(?i)^.*\.(mp3|ogg|ts|wav|wave|m3u|pls|e2pls|mpg|vob)", useServiceRef = True, additionalExtensions = "4098:m3u 4098:e2pls 4098:pls")
                self["filelist"] = self.filelist
 
                self.playlist = MyPlayList()
                self["filelist"] = self.filelist
 
                self.playlist = MyPlayList()
@@ -160,6 +161,7 @@ class MediaPlayer(Screen, InfoBarSeek, InfoBarAudioSelection, InfoBarCueSheetSup
                self.currList = "filelist"
 
                self.coverArtFileName = ""
                self.currList = "filelist"
 
                self.coverArtFileName = ""
+               self.isAudioCD = False
 
                self.playlistIOInternal = PlaylistIOInternal()
                list = self.playlistIOInternal.open(resolveFilename(SCOPE_CONFIG, "playlist.e2pls"))
 
                self.playlistIOInternal = PlaylistIOInternal()
                list = self.playlistIOInternal.open(resolveFilename(SCOPE_CONFIG, "playlist.e2pls"))
@@ -182,7 +184,8 @@ class MediaPlayer(Screen, InfoBarSeek, InfoBarAudioSelection, InfoBarCueSheetSup
                        self.playlistIOInternal.clear()
                        for x in self.playlist.list:
                                self.playlistIOInternal.addService(ServiceReference(x[0]))
                        self.playlistIOInternal.clear()
                        for x in self.playlist.list:
                                self.playlistIOInternal.addService(ServiceReference(x[0]))
-                       self.playlistIOInternal.save(resolveFilename(SCOPE_CONFIG, "playlist.e2pls"))
+                       if not self.isAudioCD:
+                               self.playlistIOInternal.save(resolveFilename(SCOPE_CONFIG, "playlist.e2pls"))
                        self.close()
 
        def checkSkipShowHideLock(self):
                        self.close()
 
        def checkSkipShowHideLock(self):
@@ -727,7 +730,7 @@ class MediaPlayerLCDScreen(Screen):
                        self["text4"].setText(text)
 
 def main(session, **kwargs):
                        self["text4"].setText(text)
 
 def main(session, **kwargs):
-        session.open(MediaPlayer)
+       session.open(MediaPlayer)
 
 def menu(menuid, **kwargs):
        if menuid == "mainmenu":
 
 def menu(menuid, **kwargs):
        if menuid == "mainmenu":
@@ -748,6 +751,24 @@ def filescan_open(list, session, **kwargs):
        mp.playServiceRefEntry(ref)
        mp.playlist.updateList()
 
        mp.playServiceRefEntry(ref)
        mp.playlist.updateList()
 
+def audioCD_open(list, session, **kwargs):
+       from enigma import eServiceReference
+
+       mp = session.open(MediaPlayer)
+
+       mp.playlist.clear()
+       mp.isAudioCD = True
+
+       mp.switchToPlayList()
+       for file in list:
+               ref = eServiceReference(4097, 0, file.path)
+               mp.playlist.addFile(ref)
+
+       # TODO: rather play first than last file?
+       mp.playServiceRefEntry(ref)
+       mp.playlist.updateList()
+       mp.changeEntry(0)
+
 def filescan(**kwargs):
        from Components.Scanner import Scanner, ScanPath
        return [
 def filescan(**kwargs):
        from Components.Scanner import Scanner, ScanPath
        return [
@@ -768,6 +789,15 @@ def filescan(**kwargs):
                        name = "Music",
                        description = "Play Music...",
                        openfnc = filescan_open,
                        name = "Music",
                        description = "Play Music...",
                        openfnc = filescan_open,
+               ),
+               Scanner(mimetypes = ["audio/x-cda", "audio/x-wav"],
+                       paths_to_scan =
+                               [
+                                       ScanPath(path = "", with_subdirs = False),
+                               ],
+                       name = "Audio-CD",
+                       description = "Play Audio-CD...",
+                       openfnc = audioCD_open,
                )
        ]
 
                )
        ]