Fixed some "crashes" that occurred on track control button presses when the current_playlist variable was empty.
This commit is contained in:
parent
d3a6cb7dd8
commit
fac2dc0f1b
2 changed files with 23 additions and 17 deletions
|
@ -5,6 +5,7 @@ from dataclasses import dataclass
|
|||
|
||||
@dataclass
|
||||
class PlayState:
|
||||
has_tracks: bool=False
|
||||
playing: bool=False
|
||||
paused: bool=False
|
||||
searched: bool=False
|
||||
|
|
|
@ -41,6 +41,7 @@ class Player:
|
|||
self.current_playlist_index = 0
|
||||
self.playing_segment = self.playing_track.sound
|
||||
self.playing_segment_duration = self.playing_track.duration
|
||||
self.play_state.has_tracks = len(self.current_playlist) > 0
|
||||
|
||||
def track_finished(self):
|
||||
self.current_playlist_index += 1
|
||||
|
@ -58,10 +59,11 @@ class Player:
|
|||
self.stop()
|
||||
|
||||
def start_playing(self):
|
||||
self.music_channel.play(self.playing_track.sound)
|
||||
self.track_progress.start()
|
||||
self.play_state.paused = False
|
||||
self.play_state.playing = True
|
||||
if self.play_state.has_tracks:
|
||||
self.music_channel.play(self.playing_track.sound)
|
||||
self.track_progress.start()
|
||||
self.play_state.paused = False
|
||||
self.play_state.playing = True
|
||||
|
||||
def pause(self):
|
||||
self.music_channel.pause()
|
||||
|
@ -74,9 +76,10 @@ class Player:
|
|||
self.play_state.paused = False
|
||||
|
||||
def skip_current(self):
|
||||
self.music_channel.stop()
|
||||
self.track_progress.stop()
|
||||
self.track_finished()
|
||||
if self.play_state.has_tracks:
|
||||
self.music_channel.stop()
|
||||
self.track_progress.stop()
|
||||
self.track_finished()
|
||||
|
||||
def previous_track(self):
|
||||
if self.current_playlist_index > 0:
|
||||
|
@ -104,16 +107,18 @@ class Player:
|
|||
self.start_playing()
|
||||
|
||||
def stop(self):
|
||||
self.music_channel.stop()
|
||||
self.track_progress.stop()
|
||||
self.play_state.playing = False
|
||||
self.playing_segment_duration = self.playing_track.duration
|
||||
if self.play_state.has_tracks:
|
||||
self.music_channel.stop()
|
||||
self.track_progress.stop()
|
||||
self.play_state.playing = False
|
||||
self.playing_segment_duration = self.playing_track.duration
|
||||
|
||||
def seek(self, position: int):
|
||||
self.play_state.searched = True
|
||||
self.music_channel.stop()
|
||||
self.track_progress.stop()
|
||||
(self.playing_segment, self.playing_segment_duration) = self.playing_track.remaining(position)
|
||||
self.music_channel.play(self.playing_segment)
|
||||
self.track_progress.start()
|
||||
if self.play_state.has_tracks:
|
||||
self.play_state.searched = True
|
||||
self.music_channel.stop()
|
||||
self.track_progress.stop()
|
||||
(self.playing_segment, self.playing_segment_duration) = self.playing_track.remaining(position)
|
||||
self.music_channel.play(self.playing_segment)
|
||||
self.track_progress.start()
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue