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() +