from os import path from menu import Menu, MenuType from cinput import ControlInput from graphics import Graphics from icecream import ic from mpv import MPV class MusicPlayer: def __init__(self, cinput: ControlInput, graphics: Graphics, menu: Menu): self._cinput = cinput self._graphics = graphics self._menu = menu def run(self): while True: item = self._menu.get_selection() if item.menu_type == MenuType.CMD: if item.data["mode"] == "album": self._play_dir(item.data["dir"], False) elif item.data["mode"] == "random": self._play_dir(item.data["dir"], True) elif item.data["mode"] == "single": self._play_track(item.data["dir"], item.data["track"]) elif item.data["mode"] == "resume": self._play_resume(item.data["dir"]) elif item.menu_type == MenuType.BACK: return def _play_dir(self, directory: str, random: bool): ic("Playing", directory, random) return def _play_track(self, directory: str, track: str): ic("Playing", track) self._draw_now_playing(track) player = MPV() player.play(path.join(directory, track)) return def _play_resume(self, directory: str): ic("Resuming", directory) return def _draw_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)