trying to play a track

This commit is contained in:
Rudis Muiznieks 2022-12-28 11:50:37 -06:00
parent c0be9136a5
commit a92e22a3ba
Signed by: rudism
GPG Key ID: CABF2F86EF7884F9
2 changed files with 24 additions and 2 deletions

View File

@ -26,7 +26,7 @@ def create_directory_menu(directory: str, dirname: str, is_resume: bool):
track_menu.append(MenuItem(fname, MenuType.CMD, { track_menu.append(MenuItem(fname, MenuType.CMD, {
"dir": directory, "dir": directory,
"mode": "single", "mode": "single",
"track": fname})) "track": path.join(directory, fname)}))
if len(dir_menu) > 0: if len(dir_menu) > 0:
return MenuItem(dirname, MenuType.SUB_MENU, {"sub_menu": dir_menu}) return MenuItem(dirname, MenuType.SUB_MENU, {"sub_menu": dir_menu})
else: else:

View File

@ -1,6 +1,7 @@
from menu import Menu, MenuType from menu import Menu, MenuType
from cinput import ControlInput from cinput import ControlInput
from graphics import Graphics from graphics import Graphics
from mpv import MPV
class MusicPlayer: class MusicPlayer:
def __init__(self, cinput: ControlInput, graphics: Graphics, menu: Menu): def __init__(self, cinput: ControlInput, graphics: Graphics, menu: Menu):
@ -11,5 +12,26 @@ class MusicPlayer:
def run(self): def run(self):
while True: while True:
item = self._menu.get_selection() item = self._menu.get_selection()
if item.menu_type == MenuType.BACK: 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"] == "track":
self._play_track(item.data["track"])
elif item.data["mode"] == "resume":
self._play_resume(item.data["dir"])
elif item.menu_type == MenuType.BACK:
return return
def _play_dir(self, directory: str, random: bool):
return
def _play_track(self, track: str):
player = MPV()
player.play(track)
player.wait_for_playback()
return
def _play_resume(self, directory: str):
return