sync screen

This commit is contained in:
Karl 2021-11-09 11:26:01 +00:00
parent e0f4c06676
commit 8b433e77f4

View File

@ -11,16 +11,16 @@ from datetime import datetime
@retry(stop=stop_after_attempt(5)) @retry(stop=stop_after_attempt(5))
def current_track(): def current_track():
mopidy = MopidyClient() mopidy = MopidyClient()
if mopidy.playback.get_state() == "stopped": if mopidy.playback.get_state(timeout=5) == "stopped":
oled.text("Nothing", 32, 26, 1) oled.text("Nothing", 32, 26, 1)
oled.text("Playing", 32, 36, 1) oled.text("Playing", 32, 36, 1)
return return
if mopidy.playback.get_state() == "paused": if mopidy.playback.get_state(timeout=5) == "paused":
oled.text("Paused", 32, 36, 1) oled.text("Paused", 32, 36, 1)
return return
current_track_data = mopidy.playback.get_current_track() current_track_data = mopidy.playback.get_current_track(timeout=5)
time_position = datetime.fromtimestamp( time_position = datetime.fromtimestamp(
mopidy.playback.get_time_position() / 1000.0 mopidy.playback.get_time_position(timeout=5) / 1000.0
).strftime("%M:%S") ).strftime("%M:%S")
if "ytmusic" in current_track_data["uri"]: if "ytmusic" in current_track_data["uri"]:
if "album" in current_track_data: if "album" in current_track_data:
@ -47,7 +47,7 @@ def current_track():
} }
else: else:
try: try:
stream_title = mopidy.playback.get_stream_title() stream_title = mopidy.playback.get_stream_title(timeout=5)
artist_and_song = stream_title.split(" - ") artist_and_song = stream_title.split(" - ")
except: except:
stream_title = "None" stream_title = "None"
@ -79,6 +79,6 @@ while True:
oled.text("Floppy Player", 26, 0, 1) oled.text("Floppy Player", 26, 0, 1)
current_track() current_track()
oled.show() oled.show()
time.sleep(2) time.sleep(3)