Undid some "OOPing" that just made it unnecessarily more complicated.
This commit is contained in:
parent
fac2dc0f1b
commit
d453afc6d0
3 changed files with 22 additions and 29 deletions
|
@ -38,7 +38,7 @@ class GUICommunication:
|
|||
self.app.player.seek(self.track_control.track_progress_slider.value())
|
||||
|
||||
def on_track_start(self):
|
||||
if self.app.player.play_state.playing:
|
||||
if self.app.player.playing:
|
||||
duration = self.app.player.playing_track.duration
|
||||
|
||||
self.track_control.track_progress_slider.setRange(
|
||||
|
@ -51,7 +51,7 @@ class GUICommunication:
|
|||
self.update_progress()
|
||||
|
||||
def update_progress(self):
|
||||
if self.app.player.play_state.playing and not self.track_progress_slider_dragged:
|
||||
if self.app.player.playing and not self.track_progress_slider_dragged:
|
||||
remaining = self.app.player.track_progress.timer.remainingTime()
|
||||
|
||||
if remaining == -1:
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from dataclasses import dataclass
|
||||
|
||||
|
||||
@dataclass
|
||||
class PlayState:
|
||||
has_tracks: bool=False
|
||||
playing: bool=False
|
||||
paused: bool=False
|
||||
searched: bool=False
|
|
@ -6,19 +6,23 @@ import pygame.mixer
|
|||
import pygame.event
|
||||
from .track import Track
|
||||
from .track_progress_timer import TrackProgress
|
||||
from .play_state import PlayState
|
||||
|
||||
|
||||
class Player:
|
||||
def __init__(self, app):
|
||||
self.app = app
|
||||
self.track_progress = TrackProgress(self.app)
|
||||
self.play_state = PlayState()
|
||||
|
||||
pygame.mixer.init()
|
||||
self.mixer = pygame.mixer
|
||||
self.music_channel = self.mixer.Channel(0)
|
||||
|
||||
self.track_progress = TrackProgress(self.app)
|
||||
|
||||
self.playing = False
|
||||
self.paused = False
|
||||
self.has_tracks = False
|
||||
self.searched = False
|
||||
|
||||
self.current_playlist = []
|
||||
self.playing_track = None
|
||||
self.current_playlist_index = 0
|
||||
|
@ -41,7 +45,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
|
||||
self.has_tracks = len(self.current_playlist) > 0
|
||||
|
||||
def track_finished(self):
|
||||
self.current_playlist_index += 1
|
||||
|
@ -59,24 +63,24 @@ class Player:
|
|||
self.stop()
|
||||
|
||||
def start_playing(self):
|
||||
if self.play_state.has_tracks:
|
||||
if self.has_tracks:
|
||||
self.music_channel.play(self.playing_track.sound)
|
||||
self.track_progress.start()
|
||||
self.play_state.paused = False
|
||||
self.play_state.playing = True
|
||||
self.paused = False
|
||||
self.playing = True
|
||||
|
||||
def pause(self):
|
||||
self.music_channel.pause()
|
||||
self.track_progress.pause()
|
||||
self.play_state.paused = True
|
||||
self.paused = True
|
||||
|
||||
def unpause(self):
|
||||
self.music_channel.unpause()
|
||||
self.track_progress.unpause()
|
||||
self.play_state.paused = False
|
||||
self.paused = False
|
||||
|
||||
def skip_current(self):
|
||||
if self.play_state.has_tracks:
|
||||
if self.has_tracks:
|
||||
self.music_channel.stop()
|
||||
self.track_progress.stop()
|
||||
self.track_finished()
|
||||
|
@ -97,25 +101,25 @@ class Player:
|
|||
self.app.gui_communication.on_track_start()
|
||||
|
||||
def toggle_playing(self):
|
||||
if self.play_state.playing and self.play_state.paused:
|
||||
if self.playing and self.paused:
|
||||
self.unpause()
|
||||
|
||||
elif self.play_state.playing:
|
||||
elif self.playing:
|
||||
self.pause()
|
||||
|
||||
else:
|
||||
self.start_playing()
|
||||
|
||||
def stop(self):
|
||||
if self.play_state.has_tracks:
|
||||
if self.has_tracks:
|
||||
self.music_channel.stop()
|
||||
self.track_progress.stop()
|
||||
self.play_state.playing = False
|
||||
self.playing = False
|
||||
self.playing_segment_duration = self.playing_track.duration
|
||||
|
||||
def seek(self, position: int):
|
||||
if self.play_state.has_tracks:
|
||||
self.play_state.searched = True
|
||||
if self.has_tracks:
|
||||
self.searched = True
|
||||
self.music_channel.stop()
|
||||
self.track_progress.stop()
|
||||
(self.playing_segment, self.playing_segment_duration) = self.playing_track.remaining(position)
|
||||
|
|
Loading…
Reference in a new issue