From f52c6cc418c2f8eb7e723d2ec1e6ed6fc01e70ff Mon Sep 17 00:00:00 2001 From: Wiktor Zykubek Date: Tue, 13 Jun 2023 00:06:24 +0200 Subject: [PATCH] Implement playback control and add icons --- form.ui | 3 +++ mainwindow.py | 14 +++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/form.ui b/form.ui index 558343b..10dd1d0 100644 --- a/form.ui +++ b/form.ui @@ -90,6 +90,9 @@ ... + + + diff --git a/mainwindow.py b/mainwindow.py index 39dff37..ba9aaf4 100644 --- a/mainwindow.py +++ b/mainwindow.py @@ -4,6 +4,7 @@ import sys from PySide6.QtCore import QUrl from PySide6.QtWidgets import QApplication, QMainWindow from PySide6.QtMultimedia import QMediaPlayer, QAudioOutput +from PySide6.QtGui import QIcon # Important: # You need to run the following command to generate the ui_form.py file @@ -29,6 +30,7 @@ class MainWindow(QMainWindow): self.getGroups() self.ui.groupslistWidget.itemClicked.connect(self.getStations) self.ui.stationslistWidget.itemClicked.connect(self.playRadio) + self.ui.toolButton.clicked.connect(self.togglePlayer) def getGroups(self): for el in self.stations_slug["groups"]: @@ -54,7 +56,17 @@ class MainWindow(QMainWindow): stream_url = f"http://stream.open.fm/{ch['id']}" self.__player.setSource(QUrl(stream_url)) - self.__player.play() + self.ui.toolButton.setIcon(QIcon.fromTheme("media-playback-start")) + + def togglePlayer(self): + if self.__player.playbackState() == QMediaPlayer.PlaybackState.PlayingState: + self.__player.stop() + self.ui.toolButton.setIcon(QIcon.fromTheme("media-playback-start")) + elif self.__player.playbackState() == QMediaPlayer.PlaybackState.StoppedState: + self.__player.play() + self.ui.toolButton.setIcon(QIcon.fromTheme("media-playback-stop")) + else: + pass if __name__ == "__main__":