Connected PlaylistView.itemDoubleClicked to a function that then tells the player to play that track.

This commit is contained in:
The Wobbler 2024-12-29 14:31:21 +01:00
parent 8fbb40d2f9
commit da27963884
5 changed files with 34 additions and 6 deletions

View file

@ -52,6 +52,15 @@ class Player:
self.track_progress.start()
self.app.gui_communication.on_track_start()
def play_track_in_playlist(self, track_index):
self.stop()
self.current_sound, self.current_sound_duration = self.current_playlist.set_track(track_index)
self.play()
self.track_progress.start()
self.app.gui_communication.on_track_start()
def pause(self):
self.music_channel.pause()
self.track_progress.pause()

View file

@ -36,11 +36,14 @@ class Playlist:
print(lines)
i = 0
num_lines = len(lines)
while i < len(lines):
while i < num_lines:
line = lines[i]
if line.startswith("#") or line.startswith("http"): # filter out comments, extended m3u and urls
i += 1
continue
self.tracks.append(Track(self.app, line, cache=i==0)) # first track is cached
@ -68,7 +71,6 @@ class Playlist:
if not self.current_track.cached: # make sure the track is cached because else the player can't play it
self.current_track.cache()
self.current_track.cached = True
return self.current_track.sound, self.current_track.duration
@ -81,7 +83,16 @@ class Playlist:
if not self.current_track.cached: # make sure the track is cached because else the player can't play it
self.current_track.cache()
self.current_track.cached = True
return self.current_track.sound, self.current_track.duration
def set_track(self, track_index):
self.current_track_index = track_index
self.current_track = self.tracks[self.current_track_index]
if not self.current_track.cached:
self.current_track.cache()
return self.current_track.sound, self.current_track.duration

View file

@ -15,15 +15,15 @@ class Track:
self.app = app
self.path = path
self.property_string = property_string
self.cached = cache
self.tags = TinyTag.get(self.path)
self.cached = False
self.audio = None
self.sound = None
self.duration = 0
if self.cached:
if cache:
self.cache()
def cache(self):
@ -36,6 +36,8 @@ class Track:
self.duration = len(self.audio) # track duration in milliseconds
self.cached = True
def remaining(self, position: int):
remaining_audio = self.audio[position:]