starting on music player

This commit is contained in:
Rudis Muiznieks 2022-12-28 10:14:33 -06:00
parent 888f777705
commit 10f7213658
Signed by: rudism
GPG key ID: CABF2F86EF7884F9
2 changed files with 35 additions and 0 deletions

View file

@ -0,0 +1,22 @@
from os import path, listdir
from menu import Menu, MenuItem, MenuType
from cinput import ControlInput
from graphics import Graphics
from .player import MusicPlayer
def execute(cinput: ControlInput, graphics: Graphics, directory: str):
current_dir = path.join("/home/rudism", directory)
top_menu = create_directory_menu(current_dir, "music")
menu = Menu(top_menu.data["sub_dir"], cinput, graphics)
MusicPlayer(cinput, graphics, menu).run()
def create_directory_menu(directory: str, dirname: str):
sub_menu = list()
for fname in listdir(directory):
new_path = path.join(directory, fname)
if path.isdir(new_path):
sub_menu.append(create_directory_menu(new_path, fname))
if len(sub_menu) > 0:
return MenuItem(dirname, MenuType.SUB_MENU, {"sub_menu": sub_menu})
else:
return MenuItem(dirname, MenuType.CMD, {"directory": directory})

13
plugin/music/player.py Normal file
View file

@ -0,0 +1,13 @@
from menu import Menu
from cinput import ControlInput
from graphics import Graphics
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:
self._menu.get_selection()