Connected PlaylistView.itemDoubleClicked to a function that then tells the player to play that track.
This commit is contained in:
parent
8fbb40d2f9
commit
da27963884
5 changed files with 34 additions and 6 deletions
|
@ -30,15 +30,21 @@ class Library:
|
|||
playlist_view = self.create_playlist_view(playlist)
|
||||
playlist_tabs.playlists[playlist.title] = playlist_view
|
||||
playlist_tabs.addTab(playlist_view, playlist.title)
|
||||
playlist_view.itemDoubleClicked.connect(self.on_track_doubleclick)
|
||||
|
||||
def create_playlist_view(self, playlist: Playlist):
|
||||
view = PlaylistView()
|
||||
|
||||
for track in playlist.tracks:
|
||||
track_item = QTreeWidgetItem(view)
|
||||
track_item.track = track
|
||||
track_item.setText(1, track.tags.title)
|
||||
track_item.setText(2, track.tags.artist)
|
||||
track_item.setText(3, track.tags.album)
|
||||
|
||||
return view
|
||||
|
||||
def on_track_doubleclick(self, item, column):
|
||||
index = item.treeWidget().indexOfTopLevelItem(item)
|
||||
self.app.player.play_track_in_playlist(index)
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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:]
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ class MainWindow(QMainWindow):
|
|||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
|
||||
self.setWindowTitle("WoBuzz")
|
||||
self.setWindowTitle("Wobuzz")
|
||||
|
||||
self.menu_bar = self.menuBar()
|
||||
|
||||
|
|
Loading…
Reference in a new issue