adding progress indicator

This commit is contained in:
Rudis Muiznieks 2022-12-28 12:38:16 -06:00
parent 1034115090
commit 753aa11f2c
Signed by: rudism
GPG Key ID: CABF2F86EF7884F9
1 changed files with 22 additions and 4 deletions

View File

@ -32,7 +32,7 @@ class MusicPlayer:
def _play_track(self, directory: str, track: str):
ic("Playing", track)
self._draw_now_playing(track)
self._init_now_playing(track)
player = MPV()
player.play(path.join(directory, track))
return
@ -41,8 +41,26 @@ class MusicPlayer:
ic("Resuming", directory)
return
def _draw_now_playing(self, track_name: str):
def _init_now_playing(self, track_name: str):
self._graphics.clear()
self._graphics.rect(0, 0, 128, 64, 1)
self._graphics.text(track_name, 2, 2, 1)
self._graphics.text(track_name, 0, 0, 1)
self._graphics.text("Pos:", 0, 1, 1)
self._draw_progress(0, 0)
self._graphics.show()
def _draw_progress(self, pos: int, length: int):
pos_str = self._convert_seconds(pos)
if length == 0:
self._graphics.text(pos_str, 5, 1, 1)
else:
len_str = self._convert_seconds(length)
progress_str = "%s / %s" % (pos_str, len_str)
self._graphics.text(progress_str, 5, 1, 1)
def _convert_seconds(self, seconds: int):
seconds = seconds % (24 * 3600)
hours = seconds // 3600
seconds %= 3600
minutes = seconds // 60
seconds %= 60
return "%d:%02d:%02d" % (hours, minutes, seconds)