Mods
This commit is contained in:
parent
e38c651249
commit
ba736560da
|
@ -256,8 +256,12 @@ class Game:
|
||||||
def toggle_song() -> None:
|
def toggle_song() -> None:
|
||||||
if Game.playing_song:
|
if Game.playing_song:
|
||||||
Window.stop_audio()
|
Window.stop_audio()
|
||||||
|
Game.playing_song = False
|
||||||
else:
|
else:
|
||||||
path = str(Config.song_path)
|
path = str(Config.song_path)
|
||||||
Window.play_audio(path)
|
|
||||||
|
|
||||||
Game.playing_song = not Game.playing_song
|
def on_stop() -> None:
|
||||||
|
Game.playing_song = False
|
||||||
|
|
||||||
|
Window.play_audio(path, on_stop)
|
||||||
|
Game.playing_song = True
|
||||||
|
|
|
@ -329,12 +329,19 @@ class Window:
|
||||||
Window.root.addWidget(root)
|
Window.root.addWidget(root)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def play_audio(path: str) -> None:
|
def play_audio(path: str, on_stop: Callable[..., Any] | None = None) -> None:
|
||||||
Window.player = QMediaPlayer()
|
Window.player = QMediaPlayer()
|
||||||
Window.audio = QAudioOutput()
|
Window.audio = QAudioOutput()
|
||||||
Window.player.setAudioOutput(Window.audio)
|
Window.player.setAudioOutput(Window.audio)
|
||||||
Window.player.setSource(QUrl.fromLocalFile(path))
|
Window.player.setSource(QUrl.fromLocalFile(path))
|
||||||
Window.audio.setVolume(100)
|
Window.audio.setVolume(100)
|
||||||
|
|
||||||
|
def handle_state_change(state: QMediaPlayer.State) -> None:
|
||||||
|
if state == QMediaPlayer.StoppedState:
|
||||||
|
if on_stop:
|
||||||
|
on_stop()
|
||||||
|
|
||||||
|
Window.player.playbackStateChanged.connect(handle_state_change)
|
||||||
Window.player.play()
|
Window.player.play()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
Loading…
Reference in New Issue