start working on adding song info inside player
This commit is contained in:
4
app.py
4
app.py
@@ -1,7 +1,7 @@
|
|||||||
import pyray as pr
|
import pyray as pr
|
||||||
import math
|
import math
|
||||||
from ctypes import c_float
|
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 ---
|
# --- Configuration Constants ---
|
||||||
INITIAL_SCREEN_WIDTH = 800
|
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.init_window(state["screen_width"], state["screen_height"], "UgPod")
|
||||||
pr.set_target_fps(TARGET_FPS)
|
pr.set_target_fps(TARGET_FPS)
|
||||||
|
|
||||||
player = FFQueuePlayer()
|
player = GaplessPlayer()
|
||||||
|
|
||||||
print("add queue")
|
print("add queue")
|
||||||
player.add_to_queue(build_jellyfin_audio_url(server["address"], client.jellyfin.get_item("dab6efb24bb2372794d2b4fb53a12376")["Id"], server["AccessToken"], server["UserId"]))
|
player.add_to_queue(build_jellyfin_audio_url(server["address"], client.jellyfin.get_item("dab6efb24bb2372794d2b4fb53a12376")["Id"], server["AccessToken"], server["UserId"]))
|
||||||
|
|||||||
@@ -17,36 +17,41 @@ import queue
|
|||||||
import sys
|
import sys
|
||||||
import io
|
import io
|
||||||
import fcntl
|
import fcntl
|
||||||
|
from dataclasses import dataclass
|
||||||
|
|
||||||
os.makedirs("logs", exist_ok=True)
|
os.makedirs("logs", exist_ok=True)
|
||||||
|
|
||||||
class FFQueuePlayer:
|
@dataclass
|
||||||
def __init__(self, samplerate=44100, channels=2):
|
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.samplerate = samplerate
|
||||||
self.channels = channels
|
self.channels = channels
|
||||||
|
|
||||||
self.proc = None
|
self.proc = None
|
||||||
self.next_proc = None
|
self.next_proc = None
|
||||||
|
|
||||||
self.current_file = None
|
self.current_song: Song = None
|
||||||
self.next_file = None
|
self.next_file: Song = None
|
||||||
|
|
||||||
self.next_preload_state = 0
|
self.next_preload_state = 0
|
||||||
|
|
||||||
self.last_sample = 0.0
|
|
||||||
self.samples_since_last_sample = 0
|
|
||||||
|
|
||||||
self.closed=False
|
self.closed=False
|
||||||
|
|
||||||
self.playing = False
|
self.playing = False
|
||||||
self.position = 0.0
|
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.current_song_in_list = -1
|
||||||
self.swap_pending = False
|
|
||||||
|
|
||||||
self.lock = threading.Lock()
|
self.lock = threading.Lock()
|
||||||
|
|
||||||
@@ -73,7 +78,7 @@ class FFQueuePlayer:
|
|||||||
"-"
|
"-"
|
||||||
],
|
],
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=open('logs/'+str(self.song)+".txt", "wb")
|
stderr=subprocess.PIPE
|
||||||
)
|
)
|
||||||
|
|
||||||
# --- make stdout non-blocking ---
|
# --- make stdout non-blocking ---
|
||||||
@@ -117,8 +122,8 @@ class FFQueuePlayer:
|
|||||||
print("ffprobe error:", e)
|
print("ffprobe error:", e)
|
||||||
|
|
||||||
return None
|
return None
|
||||||
def add_to_queue(self, url):
|
def add_to_queue(self, song:Song):
|
||||||
self.song_queue.put_nowait(url)
|
self.current_song_in_list.append(song)
|
||||||
|
|
||||||
def play(self):
|
def play(self):
|
||||||
with self.lock:
|
with self.lock:
|
||||||
Reference in New Issue
Block a user