diff --git a/wobuzz/player/play_state.py b/wobuzz/player/play_state.py index f538b84..39fe26b 100644 --- a/wobuzz/player/play_state.py +++ b/wobuzz/player/play_state.py @@ -5,6 +5,7 @@ from dataclasses import dataclass @dataclass class PlayState: + has_tracks: bool=False playing: bool=False paused: bool=False searched: bool=False diff --git a/wobuzz/player/player.py b/wobuzz/player/player.py index 297f17d..6b587b5 100644 --- a/wobuzz/player/player.py +++ b/wobuzz/player/player.py @@ -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()