From 88b846f3b6319c2cca3966725c834519d1315de4 Mon Sep 17 00:00:00 2001 From: EKNr1 Date: Sat, 25 Jan 2025 16:17:42 +0100 Subject: [PATCH] Made the player always cache also the next track when Player.play() gets executed so that there is completely no delay when the track finished and a new track starts. --- wobuzz/player/player.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/wobuzz/player/player.py b/wobuzz/player/player.py index 8f085e7..0bb4700 100644 --- a/wobuzz/player/player.py +++ b/wobuzz/player/player.py @@ -1,5 +1,6 @@ #!/usr/bin/python3 +import threading import pygame.mixer import pygame.event from .playlist import Playlist @@ -32,6 +33,10 @@ class Player: self.app.gui.track_control.on_playstate_update() + # cache next track so it immediately starts when the current track finishes + caching_thread = threading.Thread(target=self.cache_next_track) + caching_thread.start() + def track_finished(self): if not self.current_playlist.on_last_track(): previous_track = self.current_playlist.current_track @@ -122,3 +127,14 @@ class Player: self.play() self.track_progress.start() + def cache_next_track(self): + # cache the next track + # (usually run in separate thread) + if self.current_playlist.on_last_track(): + return + + track = self.current_playlist.tracks[self.current_playlist.current_track_index + 1] + + if not track.cached: + track.cache() +