def getThemePlaylist(self): # Take the list of files and create a playlist from them # Needs to be a Music playlist otherwise repeat will not work # via the JSON interface playlist = xbmc.PlayList(xbmc.PLAYLIST_MUSIC) playlist.clear() for aFile in self.themeFiles: # Add the theme file to a playlist playlist.add(url=aFile) # Check if we have more than one item in the playlist if playlist.size() > 1: # Check if we need to perform a shuffle of the available themes if (not self.doNotShuffle) and (Settings.isShuffleThemes() or self.forceShuffle): playlist.shuffle() # Check if we are only supposed to play one theme when there are multiple # available if Settings.onlyPlaySingleTheme(): firstTheme = playlist[0].getfilename() playlist.clear() playlist.add(url=firstTheme) # Now we have the playlist, and it has been shuffled if needed # Check if we need to have a random start time for the first track # Note: The following method (rather than seek) should prevent # the seek dialog being displayed on the screen and also prevent # the need to start the theme playing before changing the start point if Settings.isRandomStart() and playlist.size() > 0: filename = playlist[0].getfilename() duration = int(playlist[0].getduration()) log("ThemeFiles: Duration is %d for file %s" % (duration, filename), self.debug_logging_enabled) # Check if the duration of the file is showing as Zero, this means we need to # try and find out the duration ourself if duration < 1: duration = VideoParser().getVideoLength(filename) log("ThemeFiles: Manual find of duration is %d for file %s" % (duration, filename), self.debug_logging_enabled) if duration > 10: listitem = xbmcgui.ListItem() # Check if there is a fixed start position randomStart = Settings.getRandomFixedOffset(filename) if (randomStart < 1) or (randomStart >= duration): # Record if the theme should start playing part-way through randomStart = random.randint(0, int(duration * 0.75)) listitem.setProperty('StartOffset', str(randomStart)) log("ThemeFiles: Setting Random start of %d for %s" % (randomStart, filename), self.debug_logging_enabled) # Remove the old item from the playlist playlist.remove(filename) # Add the new item at the start of the list playlist.add(filename, listitem, 0) return playlist