diff --git a/src/jukebox/components/playermpd/__init__.py b/src/jukebox/components/playermpd/__init__.py index 04f0643c1..71dc87d42 100644 --- a/src/jukebox/components/playermpd/__init__.py +++ b/src/jukebox/components/playermpd/__init__.py @@ -418,7 +418,7 @@ def resume(self): self.mpd_client.play() @plugs.tag - def play_card(self, folder: str, recursive: bool = False): + def play_card(self, folder: str, recursive: bool = False, resume: bool = False): """ Main entry point for trigger music playing from RFID reader. Decodes second swipe options before playing folder content @@ -427,6 +427,7 @@ def play_card(self, folder: str, recursive: bool = False): :param folder: Folder path relative to music library path :param recursive: Add folder recursively + :param resume: Try to resume from last position? """ # Developers notes: # @@ -447,7 +448,7 @@ def play_card(self, folder: str, recursive: bool = False): self.second_swipe_action() else: logger.debug('Calling first swipe action') - self.play_folder(folder, recursive) + self.play_folder(folder, recursive, resume=resume) @plugs.tag def get_folder_content(self, folder: str): @@ -463,7 +464,8 @@ def get_folder_content(self, folder: str): return plc.playlist @plugs.tag - def play_folder(self, folder: str, recursive: bool = False) -> None: + def play_folder(self, folder: str, recursive: bool = False, + resume: bool = False) -> None: """ Playback a music folder. @@ -472,6 +474,7 @@ def play_folder(self, folder: str, recursive: bool = False) -> None: :param folder: Folder path relative to music library path :param recursive: Add folder recursively + :param resume: Try to resume from previous state? """ # TODO: This changes the current state -> Need to save last state with self.mpd_lock: @@ -491,11 +494,23 @@ def play_folder(self, folder: str, recursive: bool = False) -> None: self.music_player_status['player_status']['last_played_folder'] = folder + # Here a reference to the folder dict is used. + # Thus any update to the current_folder_status dict will + # be reflected in the dict of the corresponding folder self.current_folder_status = self.music_player_status['audio_folder_status'].get(folder) if self.current_folder_status is None: self.current_folder_status = self.music_player_status['audio_folder_status'][folder] = {} - - self.mpd_client.play() + # Dont attempt to resume, if this is a new folder + self.mpd_client.play() + else: + if resume: + try: + self.resume() + except mpd.base.CommandError as e: + logger.exception("Failed to resume folder: %s", folder) + self.mpd_client.play() + else: + self.mpd_client.play() @plugs.tag def play_album(self, albumartist: str, album: str):