start working on adding song info inside player

This commit is contained in:
William Bell
2025-12-12 12:55:53 +00:00
parent e2f4e699dc
commit 8496e6871b
2 changed files with 22 additions and 17 deletions

4
app.py
View File

@@ -1,7 +1,7 @@
import pyray as pr
import math
from ctypes import c_float
from player import FFQueuePlayer, build_jellyfin_audio_url, server, client
from gapless_player import GaplessPlayer, build_jellyfin_audio_url, server, client
# --- Configuration Constants ---
INITIAL_SCREEN_WIDTH = 800
@@ -173,7 +173,7 @@ pr.set_config_flags(pr.FLAG_MSAA_4X_HINT)
pr.init_window(state["screen_width"], state["screen_height"], "UgPod")
pr.set_target_fps(TARGET_FPS)
player = FFQueuePlayer()
player = GaplessPlayer()
print("add queue")
player.add_to_queue(build_jellyfin_audio_url(server["address"], client.jellyfin.get_item("dab6efb24bb2372794d2b4fb53a12376")["Id"], server["AccessToken"], server["UserId"]))

View File

@@ -17,36 +17,41 @@ import queue
import sys
import io
import fcntl
from dataclasses import dataclass
os.makedirs("logs", exist_ok=True)
class FFQueuePlayer:
def __init__(self, samplerate=44100, channels=2):
@dataclass
class Song:
url: str
duration: float
name: str
album_name:str
album_cover:str
artist_name:str
class GaplessPlayer:
def __init__(self, samplerate:int=44100, channels:int=2):
self.samplerate = samplerate
self.channels = channels
self.proc = None
self.next_proc = None
self.current_file = None
self.next_file = None
self.current_song: Song = None
self.next_file: Song = None
self.next_preload_state = 0
self.last_sample = 0.0
self.samples_since_last_sample = 0
self.closed=False
self.playing = False
self.position = 0.0
self.playback_info = None
self.next_playback_info=None
self.song = 0
self.song_list = []
self.song_queue = queue.Queue()
self.swap_pending = False
self.current_song_in_list = -1
self.lock = threading.Lock()
@@ -73,7 +78,7 @@ class FFQueuePlayer:
"-"
],
stdout=subprocess.PIPE,
stderr=open('logs/'+str(self.song)+".txt", "wb")
stderr=subprocess.PIPE
)
# --- make stdout non-blocking ---
@@ -117,8 +122,8 @@ class FFQueuePlayer:
print("ffprobe error:", e)
return None
def add_to_queue(self, url):
self.song_queue.put_nowait(url)
def add_to_queue(self, song:Song):
self.current_song_in_list.append(song)
def play(self):
with self.lock: