2022-12-28 11:26:30 -06:00
|
|
|
from menu import Menu, MenuType
|
2022-12-28 10:14:33 -06:00
|
|
|
from cinput import ControlInput
|
|
|
|
from graphics import Graphics
|
2022-12-28 11:53:20 -06:00
|
|
|
from icecream import ic
|
2022-12-28 11:50:37 -06:00
|
|
|
from mpv import MPV
|
2022-12-28 10:14:33 -06:00
|
|
|
|
|
|
|
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:
|
2022-12-28 11:26:30 -06:00
|
|
|
item = self._menu.get_selection()
|
2022-12-28 11:50:37 -06:00
|
|
|
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)
|
2022-12-28 11:55:03 -06:00
|
|
|
elif item.data["mode"] == "single":
|
2022-12-28 11:50:37 -06:00
|
|
|
self._play_track(item.data["track"])
|
|
|
|
elif item.data["mode"] == "resume":
|
|
|
|
self._play_resume(item.data["dir"])
|
|
|
|
elif item.menu_type == MenuType.BACK:
|
2022-12-28 11:26:30 -06:00
|
|
|
return
|
2022-12-28 11:50:37 -06:00
|
|
|
|
|
|
|
def _play_dir(self, directory: str, random: bool):
|
2022-12-28 11:55:03 -06:00
|
|
|
ic("Playing", directory, random)
|
2022-12-28 11:50:37 -06:00
|
|
|
return
|
|
|
|
|
|
|
|
def _play_track(self, track: str):
|
2022-12-28 11:55:03 -06:00
|
|
|
ic("Playing", track)
|
2022-12-28 11:50:37 -06:00
|
|
|
player = MPV()
|
|
|
|
player.play(track)
|
|
|
|
player.wait_for_playback()
|
|
|
|
return
|
|
|
|
|
|
|
|
def _play_resume(self, directory: str):
|
2022-12-28 11:55:03 -06:00
|
|
|
ic("Resuming", directory)
|
2022-12-28 11:50:37 -06:00
|
|
|
return
|