Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add resume to play_card #1946

Open
wants to merge 2 commits into
base: future3/develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions src/jukebox/components/playermpd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,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

Expand All @@ -547,6 +547,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:
#
Expand Down Expand Up @@ -575,7 +576,7 @@ def play_card(self, folder: str, recursive: bool = False):
# run callbacks before play_folder is invoked
play_card_callbacks.run_callbacks(folder, PlayCardState.firstSwipe)

self.play_folder(folder, recursive)
self.play_folder(folder, recursive, resume=resume)

@plugs.tag
def get_single_coverart(self, song_url):
Expand Down Expand Up @@ -612,7 +613,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.

Expand All @@ -621,6 +623,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:
Expand All @@ -640,11 +643,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, exc_info=e)
self.mpd_client.play()
else:
self.mpd_client.play()

@plugs.tag
def play_album(self, albumartist: str, album: str):
Expand Down