0
1
mirror of https://github.com/radio95-rnt/RadioPlayer.git synced 2026-02-27 06:03:52 +01:00
This commit is contained in:
KubaPro010
2025-11-06 18:54:13 +01:00
parent 9b5bffedb6
commit 2d5d899c41
3 changed files with 31 additions and 8 deletions

26
modules/cache.py Normal file
View File

@@ -0,0 +1,26 @@
import os
from . import PlayerModule, Track
class Module(PlayerModule):
def __init__(self) -> None:
self.playlist = []
def on_new_playlist(self, playlist: list[Track]):
self.playlist = [t.path.absolute() for t in playlist]
def on_new_track(self, index: int, track: Track):
if track.path.absolute().as_posix() != self.playlist[index].as_posix():
# discrepancy, which means that the playing file was modified by the active modifier
# we are playing a file that was not determined in the playlist, that means it was chosen by the active modifier and made up on the fly
next = self.playlist[index]
else:
next = self.playlist[index+1]
with open(track.path.absolute(), "rb") as f:
os.posix_fadvise(f.fileno(), 0, 0, os.POSIX_FADV_SEQUENTIAL)
os.posix_fadvise(f.fileno(), 0, 0, os.POSIX_FADV_NOREUSE)
os.posix_fadvise(f.fileno(), 0, 0, os.POSIX_FADV_WILLNEED)
with open(next, "rb") as f:
os.posix_fadvise(f.fileno(), 0, 0, os.POSIX_FADV_SEQUENTIAL)
os.posix_fadvise(f.fileno(), 0, 0, os.POSIX_FADV_NOREUSE)
os.posix_fadvise(f.fileno(), 0, 0, os.POSIX_FADV_WILLNEED)
module = Module()

View File

@@ -1,4 +1,4 @@
from . import PlayerModule, log95, Track from . import PlayerModule, log95, Track, Popen
logger = log95.log95("PlayView") logger = log95.log95("PlayView")
@@ -6,7 +6,7 @@ class Module(PlayerModule):
def __init__(self) -> None: def __init__(self) -> None:
self.playlist = [] self.playlist = []
def on_new_playlist(self, playlist: list[Track]): def on_new_playlist(self, playlist: list[Track]):
self.playlist = [str(t.path) for t in playlist] self.playlist = [str(t.path.absolute()) for t in playlist]
def on_new_track(self, index: int, track: Track): def on_new_track(self, index: int, track: Track):
if str(track.path) != self.playlist[index]: if str(track.path) != self.playlist[index]:
# discrepancy, which means that the playing file was modified by the active modifier # discrepancy, which means that the playing file was modified by the active modifier

View File

@@ -34,23 +34,20 @@ class ProcessManager(Skeleton_ProcessManager):
return result return result
return None return None
def play(self, track: Track, fade_time: int=5) -> Process: def play(self, track: Track, fade_time: int=5) -> Process:
cmd = ['ffmpeg', '-hide_banner', '-loglevel', 'quiet'] cmd = ['ffplay', '-nodisp', '-hide_banner', '-autoexit', '-loglevel', 'quiet']
assert track.path.exists() assert track.path.exists()
duration = self._get_audio_duration(track.path.absolute()) duration = self._get_audio_duration(track.path.absolute())
if not duration: raise Exception("Failed to get file duration for", track.path) if not duration: raise Exception("Failed to get file duration for", track.path)
if track.offset >= duration: track.offset = max(duration - 0.1, 0) if track.offset >= duration: track.offset = max(duration - 0.1, 0)
if track.offset > 0: cmd.extend(['-ss', str(track.offset)])
if track.offset > 0:
cmd.extend(['-ss', str(track.offset)])
cmd.extend(['-i', str(track.path.absolute())])
filters = [] filters = []
if track.fade_in: filters.append(f"afade=t=in:st=0:d={fade_time}") if track.fade_in: filters.append(f"afade=t=in:st=0:d={fade_time}")
if track.fade_out: filters.append(f"afade=t=out:st={duration - fade_time - track.offset}:d={fade_time}") if track.fade_out: filters.append(f"afade=t=out:st={duration - fade_time - track.offset}:d={fade_time}")
if filters: cmd.extend(['-af', ",".join(filters)]) if filters: cmd.extend(['-af', ",".join(filters)])
cmd.extend(['-f', 'pulse', 'default']) cmd.append(str(track.path.absolute()))
pr = Process(Popen(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, start_new_session=True), track.path.name, time.monotonic(), duration - track.offset) pr = Process(Popen(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, start_new_session=True), track.path.name, time.monotonic(), duration - track.offset)
with self.lock: self.processes.append(pr) with self.lock: self.processes.append(pr)