Got it working, but it's not better than before...

This commit is contained in:
The Wobbler 2025-02-04 14:43:08 +01:00
parent 6134c21ce4
commit 22ffd211df
7 changed files with 48 additions and 18 deletions

View file

@ -1,5 +1,6 @@
#!/usr/bin/python3
import time
import threading
import pygame.mixer
import pygame.event
@ -174,6 +175,15 @@ class Player:
def start_playlist(self, playlist):
self.stop()
if not playlist.loaded:
playlist.load()
while not playlist.has_tracks() and not playlist.loaded: # wait until first track is loaded
time.sleep(0.1)
if not playlist.has_tracks():
return
self.current_sound, self.current_sound_duration = playlist.set_track(0) # first track
self.current_playlist = playlist

View file

@ -1,6 +1,7 @@
#!/usr/bin/python3
import os
import threading
from PyQt6.QtCore import Qt
from .track import Track
@ -18,7 +19,8 @@ class Playlist:
self.tracks: list[Track] = []
self.current_track_index = 0
self.current_track: Track | None = None
self.view = None
self.views = {} # dict of id(LibraryDock): PlaylistView
self.loaded = False
self.path = os.path.expanduser(
f"{app.settings.library_path}/playlists/{self.title.replace(" ", "_")}.wbz.m3u"
@ -41,9 +43,13 @@ class Playlist:
i += 1
# set current track to the first track if there is no currently playing track
if self.current_track is None and self.has_tracks():
self.current_track = self.tracks[0]
self.save()
self.tracks = []
def load(self):
loading_thread = threading.Thread(target=self.load_from_m3u, args=(self.path,))
loading_thread.start()
def load_from_m3u(self, path):
file = open(path, "r")
@ -64,14 +70,18 @@ class Playlist:
continue
self.tracks.append(Track(self.app, line, cache=i==0)) # first track is cached
self.append_track(Track(self.app, line, cache=i==0)) # first track is cached
i += 1
print("kolupp")
# set current track to the first track if there is no currently playing track
if self.current_track is None and self.has_tracks():
self.current_track = self.tracks[0]
self.loaded = True
def load_from_wbz(self, path):
pass
@ -149,10 +159,14 @@ class Playlist:
self.app.library.playlists.remove(self)
def append_track(self, track):
for dock_id in self.views:
view = self.views[dock_id]
view.append_track(track)
self.tracks.append(track)
if self.view:
self.view.append_track(track)
print(track.tags.title)
def h_last_track(self):
# get last track in history (only gets used in player.history)