From 08ae286797130116d673c4a2af32d15355775d5f Mon Sep 17 00:00:00 2001 From: Wiktor Zykubek Date: Wed, 14 Jun 2023 16:22:48 +0200 Subject: [PATCH] Implement volume control --- form.ui | 5 +++-- mainwindow.py | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/form.ui b/form.ui index e0c2e52..33462bb 100644 --- a/form.ui +++ b/form.ui @@ -107,7 +107,7 @@ - + 0 @@ -128,7 +128,8 @@ ... - + + .. diff --git a/mainwindow.py b/mainwindow.py index f52a23b..e3a7103 100644 --- a/mainwindow.py +++ b/mainwindow.py @@ -24,11 +24,13 @@ class MainWindow(QMainWindow): self.__player = QMediaPlayer() self.__audio = QAudioOutput() self.__player.setAudioOutput(self.__audio) - self.__audio.setVolume(self.ui.horizontalSlider_2.value()) + self.setVolume() self.getGroups() self.ui.groupslistWidget.itemClicked.connect(self.getStations) self.ui.stationslistWidget.itemClicked.connect(self.playRadio) self.ui.toolButton.clicked.connect(self.togglePlayer) + self.ui.volumeHorizontalSlider.valueChanged.connect(self.setVolume) + self.ui.volumeToolButton.clicked.connect(self.toggleMute) def getGroups(self): for el in self.stations_slug["groups"]: @@ -58,6 +60,21 @@ class MainWindow(QMainWindow): else: return json.loads(resp.text) + def setVolume(self, volume: int = None): + if volume is None: + volume = self.ui.volumeHorizontalSlider.value() + self.__audio.setVolume(volume / 100) + + def toggleMute(self): + if self.ui.volumeHorizontalSlider.value() == 0: + self.ui.volumeHorizontalSlider.setValue(70) + self.ui.volumeToolButton.setIcon(QIcon.fromTheme("audio-volume-medium")) + self.setVolume(70) + else: + self.ui.volumeHorizontalSlider.setValue(0) + self.ui.volumeToolButton.setIcon(QIcon.fromTheme("audio-volume-muted")) + self.setVolume(0) + def playRadio(self): station = self.ui.stationslistWidget.selectedItems()[0].text() stream_url = None