diff --git a/wobuzz/gui_communication.py b/wobuzz/gui_communication.py index 08d6e2b..3fa5a9e 100644 --- a/wobuzz/gui_communication.py +++ b/wobuzz/gui_communication.py @@ -25,10 +25,10 @@ class GUICommunication: self.update_progress() def update_progress(self): - remaining = self.app.player.track_progress_timer.remainingTime() + remaining = self.app.player.track_progress.timer.remainingTime() if remaining == -1: - remaining = self.app.player.remaining_time + remaining = self.app.player.track_progress.remaining_time track_duration = self.app.player.playing_track.duration diff --git a/wobuzz/player/player.py b/wobuzz/player/player.py index 9671c4c..5939e08 100644 --- a/wobuzz/player/player.py +++ b/wobuzz/player/player.py @@ -6,21 +6,18 @@ from PyQt6.QtCore import QTimer import pygame.mixer import pygame.event from .track import Track +from .track_progress_timer import TrackProgress class Player: def __init__(self, app, file_paths: list=[]): self.app = app + self.track_progress = TrackProgress(self.app) pygame.mixer.init() self.mixer = pygame.mixer self.music_channel = self.mixer.Channel(0) - self.track_progress_timer = QTimer() - self.track_progress_timer.timeout.connect(self.track_finished) - self.track_progress_timer.setSingleShot(True) - self.remaining_time = 0 - self.playing = False self.paused = False @@ -57,27 +54,28 @@ class Player: self.playing_track = self.current_playlist[self.current_playlist_index] self.music_channel.play(self.playing_track.sound) - self.start_track_progress_timer() + self.track_progress.start() self.app.gui_communication.on_track_start() def start_playing(self): self.music_channel.play(self.playing_track.sound) - self.start_track_progress_timer() + self.track_progress.start() self.paused = False self.playing = True def pause(self): self.music_channel.pause() + self.track_progress.pause() self.paused = True - self.pause_track_progress_timer() def unpause(self): self.music_channel.unpause() + self.track_progress.unpause() self.paused = False - self.unpause_track_progress_timer() def skip_current(self): self.music_channel.stop() + self.track_progress.stop() self.track_finished() def previous_track(self): @@ -86,8 +84,11 @@ class Player: self.current_playlist_index -= 1 self.playing_track = self.current_playlist[self.current_playlist_index] + self.track_progress.stop() self.music_channel.play(self.playing_track.sound) + self.track_progress.start() + self.app.gui_communication.on_track_start() def toggle_playing(self): if self.playing and self.paused: @@ -101,15 +102,6 @@ class Player: def stop(self): self.music_channel.stop() + self.track_progress.stop() self.playing = False - def start_track_progress_timer(self): - self.track_progress_timer.start(self.playing_track.duration) - - def pause_track_progress_timer(self): - self.remaining_time = self.track_progress_timer.remainingTime() - self.track_progress_timer.stop() - - def unpause_track_progress_timer(self): - self.track_progress_timer.start(self.remaining_time) - diff --git a/wobuzz/player/track_progress_timer.py b/wobuzz/player/track_progress_timer.py new file mode 100644 index 0000000..284d8ec --- /dev/null +++ b/wobuzz/player/track_progress_timer.py @@ -0,0 +1,32 @@ +#!/usr/bin/python3 + +from PyQt6.QtCore import QTimer + + +class TrackProgress: + def __init__(self, app): + self.app = app + + self.remaining_time = 0 + + self.timer = QTimer() + self.timer.timeout.connect(self.track_finished) + self.timer.setSingleShot(True) + + def track_finished(self): + self.app.player.track_finished() + + def start(self): + self.timer.start(self.app.player.playing_track.duration) + + def pause(self): + self.remaining_time = self.timer.remainingTime() + self.timer.stop() + + def unpause(self): + self.timer.start(self.remaining_time) + + def stop(self): + print(self.app.player.playing_track.path) + self.timer.stop() + self.remaining_time = self.app.player.playing_track.duration