23 lines
884 B
Python
23 lines
884 B
Python
import struct
|
|
from core.utils import console, console_err
|
|
from core.protocol import COMMANDS
|
|
|
|
class play:
|
|
def __init__(self, bus):
|
|
self.bus = bus
|
|
|
|
def get(self, path: str, interrupt: bool):
|
|
flags = 0x01 if interrupt else 0x00
|
|
path_bytes = path.encode('utf-8')
|
|
|
|
# Payload: [1 Byte Flags] + [1 Byte Path Length] + [Path String]
|
|
payload = struct.pack('B', flags) + struct.pack('B', len(path_bytes)) + path_bytes
|
|
|
|
self.bus.send_request(COMMANDS['play'], payload)
|
|
data = self.bus.receive_ack()
|
|
return data is not None and data.get('type') == 'ack'
|
|
|
|
def print(self, result, path: str, interrupt: bool):
|
|
if result:
|
|
mode = "sofort (Interrupt)" if interrupt else "in die Warteschlange (Queue)"
|
|
console.print(f"▶ Wiedergabe von [info]{path}[/info] {mode} eingereiht.") |