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())
|
self.app.player.seek(self.track_control.track_progress_slider.value())
|
||||||
|
|
||||||
def on_track_start(self):
|
def on_track_start(self):
|
||||||
if self.app.player.play_state.playing:
|
if self.app.player.playing:
|
||||||
duration = self.app.player.playing_track.duration
|
duration = self.app.player.playing_track.duration
|
||||||
|
|
||||||
self.track_control.track_progress_slider.setRange(
|
self.track_control.track_progress_slider.setRange(
|
||||||
|
@ -51,7 +51,7 @@ class GUICommunication:
|
||||||
self.update_progress()
|
self.update_progress()
|
||||||
|
|
||||||
def update_progress(self):
|
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()
|
remaining = self.app.player.track_progress.timer.remainingTime()
|
||||||
|
|
||||||
if remaining == -1:
|
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
|
import pygame.event
|
||||||
from .track import Track
|
from .track import Track
|
||||||
from .track_progress_timer import TrackProgress
|
from .track_progress_timer import TrackProgress
|
||||||
from .play_state import PlayState
|
|
||||||
|
|
||||||
|
|
||||||
class Player:
|
class Player:
|
||||||
def __init__(self, app):
|
def __init__(self, app):
|
||||||
self.app = app
|
self.app = app
|
||||||
self.track_progress = TrackProgress(self.app)
|
|
||||||
self.play_state = PlayState()
|
|
||||||
|
|
||||||
pygame.mixer.init()
|
pygame.mixer.init()
|
||||||
self.mixer = pygame.mixer
|
self.mixer = pygame.mixer
|
||||||
self.music_channel = self.mixer.Channel(0)
|
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.current_playlist = []
|
||||||
self.playing_track = None
|
self.playing_track = None
|
||||||
self.current_playlist_index = 0
|
self.current_playlist_index = 0
|
||||||
|
@ -41,7 +45,7 @@ class Player:
|
||||||
self.current_playlist_index = 0
|
self.current_playlist_index = 0
|
||||||
self.playing_segment = self.playing_track.sound
|
self.playing_segment = self.playing_track.sound
|
||||||
self.playing_segment_duration = self.playing_track.duration
|
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):
|
def track_finished(self):
|
||||||
self.current_playlist_index += 1
|
self.current_playlist_index += 1
|
||||||
|
@ -59,24 +63,24 @@ class Player:
|
||||||
self.stop()
|
self.stop()
|
||||||
|
|
||||||
def start_playing(self):
|
def start_playing(self):
|
||||||
if self.play_state.has_tracks:
|
if self.has_tracks:
|
||||||
self.music_channel.play(self.playing_track.sound)
|
self.music_channel.play(self.playing_track.sound)
|
||||||
self.track_progress.start()
|
self.track_progress.start()
|
||||||
self.play_state.paused = False
|
self.paused = False
|
||||||
self.play_state.playing = True
|
self.playing = True
|
||||||
|
|
||||||
def pause(self):
|
def pause(self):
|
||||||
self.music_channel.pause()
|
self.music_channel.pause()
|
||||||
self.track_progress.pause()
|
self.track_progress.pause()
|
||||||
self.play_state.paused = True
|
self.paused = True
|
||||||
|
|
||||||
def unpause(self):
|
def unpause(self):
|
||||||
self.music_channel.unpause()
|
self.music_channel.unpause()
|
||||||
self.track_progress.unpause()
|
self.track_progress.unpause()
|
||||||
self.play_state.paused = False
|
self.paused = False
|
||||||
|
|
||||||
def skip_current(self):
|
def skip_current(self):
|
||||||
if self.play_state.has_tracks:
|
if self.has_tracks:
|
||||||
self.music_channel.stop()
|
self.music_channel.stop()
|
||||||
self.track_progress.stop()
|
self.track_progress.stop()
|
||||||
self.track_finished()
|
self.track_finished()
|
||||||
|
@ -97,25 +101,25 @@ class Player:
|
||||||
self.app.gui_communication.on_track_start()
|
self.app.gui_communication.on_track_start()
|
||||||
|
|
||||||
def toggle_playing(self):
|
def toggle_playing(self):
|
||||||
if self.play_state.playing and self.play_state.paused:
|
if self.playing and self.paused:
|
||||||
self.unpause()
|
self.unpause()
|
||||||
|
|
||||||
elif self.play_state.playing:
|
elif self.playing:
|
||||||
self.pause()
|
self.pause()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.start_playing()
|
self.start_playing()
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
if self.play_state.has_tracks:
|
if self.has_tracks:
|
||||||
self.music_channel.stop()
|
self.music_channel.stop()
|
||||||
self.track_progress.stop()
|
self.track_progress.stop()
|
||||||
self.play_state.playing = False
|
self.playing = False
|
||||||
self.playing_segment_duration = self.playing_track.duration
|
self.playing_segment_duration = self.playing_track.duration
|
||||||
|
|
||||||
def seek(self, position: int):
|
def seek(self, position: int):
|
||||||
if self.play_state.has_tracks:
|
if self.has_tracks:
|
||||||
self.play_state.searched = True
|
self.searched = True
|
||||||
self.music_channel.stop()
|
self.music_channel.stop()
|
||||||
self.track_progress.stop()
|
self.track_progress.stop()
|
||||||
(self.playing_segment, self.playing_segment_duration) = self.playing_track.remaining(position)
|
(self.playing_segment, self.playing_segment_duration) = self.playing_track.remaining(position)
|
||||||
|
|
Loading…
Add table
Reference in a new issue