summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMavridis Philippe <mavridisf@gmail.com>2023-05-24 12:19:31 +0300
committerMavridis Philippe <mavridisf@gmail.com>2023-11-24 22:46:27 +0200
commitaee45d05095e4ceea5322ad332fea55ae897932a (patch)
tree558ff64e026b9b2eafd9e7e31634ed7d0366f51c
parent54545a0913972d357d3c2dfcb5e446bac674faf1 (diff)
downloadkaffeine-aee45d05095e4ceea5322ad332fea55ae897932a.tar.gz
kaffeine-aee45d05095e4ceea5322ad332fea55ae897932a.zip
mpvpart: added volume controls
Signed-off-by: Mavridis Philippe <mavridisf@gmail.com>
-rw-r--r--kaffeine/src/player-parts/libmpv-part/libmpv_part.cpp31
-rw-r--r--kaffeine/src/player-parts/libmpv-part/libmpv_part.h6
-rw-r--r--kaffeine/src/player-parts/libmpv-part/libmpv_part.rc8
3 files changed, 40 insertions, 5 deletions
diff --git a/kaffeine/src/player-parts/libmpv-part/libmpv_part.cpp b/kaffeine/src/player-parts/libmpv-part/libmpv_part.cpp
index a42b3c7..7f7406f 100644
--- a/kaffeine/src/player-parts/libmpv-part/libmpv_part.cpp
+++ b/kaffeine/src/player-parts/libmpv-part/libmpv_part.cpp
@@ -121,12 +121,14 @@ bool MpvPart::initMpv() {
void MpvPart::initActions()
{
+ /** Playback controls ***/
new TDEAction(i18n("Play"), "media-playback-start", 0, this, SLOT(slotPlay()), actionCollection(), "player_play");
new TDEAction(i18n("Pause"), "media-playback-pause", Key_Space, this, SLOT(slotTogglePause()), actionCollection(), "player_pause");
new TDEAction(i18n("Stop"), "media-playback-stop", Key_Backspace, this, SLOT(slotStop()), actionCollection(), "player_stop");
new TDEAction(i18n("&Previous"), "media-skip-backward", Key_PageUp, this, SLOT(slotPrevious()), actionCollection(), "player_previous");
new TDEAction(i18n("&Next"), "media-skip-forward", Key_PageDown, this, SLOT(slotNext()), actionCollection(), "player_next");
+ /*** Position toolbar ***/
// Important: we have a max of 1000 instead of 100 for better precision; multiply/divide your percentages by 10
m_position = new TQSlider(0, 1000, 10, 0, TQt::Horizontal, 0);
TQToolTip::add(m_position, i18n("Position"));
@@ -146,6 +148,13 @@ void MpvPart::initActions()
m_playtime->setFocusPolicy(TQ_NoFocus);
new KWidgetAction(m_playtime, i18n("Playtime"), 0, 0, 0, actionCollection(), "player_playtime");
+ /*** Volume toolbar ***/
+ new TDEAction(i18n("&Mute"), "player_mute", Key_U, this, SLOT(slotMute()), actionCollection(), "player_mute");
+
+ m_volume = new TQSlider(0, 100, 10, 100, TQt::Horizontal, 0);
+ connect(m_volume, SIGNAL(sliderMoved(int)), this, SLOT(slotSetVolume(int)));
+ KWidgetAction *volAction = new KWidgetAction(m_volume, i18n("Volume"), 0, 0, 0, actionCollection(), "player_volume");
+
resetTime();
}
@@ -328,6 +337,16 @@ bool MpvPart::isPaused() {
return (bool)result;
}
+bool MpvPart::isMute() {
+ if (!m_mpv) return false;
+
+ int result;
+ if (mpv_get_property(m_mpv, "ao-mute", MPV_FORMAT_FLAG, &result) < 0) {
+ return false;
+ }
+ return (bool)result;
+}
+
void MpvPart::resetTime() {
m_playtime->setText("0:00:00");
m_position->setValue(0);
@@ -349,15 +368,20 @@ void MpvPart::slotSetSeekingPos(int pos) {
}
uint MpvPart::volume() const {
- return 0;
+ int64_t value = 0;
+ mpv_get_property(m_mpv, "ao-volume", MPV_FORMAT_INT64, &value);
+ return value;
}
uint MpvPart::position() const {
return m_percent;
}
-void MpvPart::slotSetVolume(uint) {
+void MpvPart::slotSetVolume(uint volume) {
+ if (!m_mpv) return;
+ int64_t value = (int64_t)volume;
+ mpv_set_property(m_mpv, "ao-volume", MPV_FORMAT_INT64, &value);
}
void MpvPart::slotSetPosition(uint position) {
@@ -395,7 +419,8 @@ void MpvPart::slotStop() {
}
void MpvPart::slotMute() {
-
+ int value = isMute() ? 0 : 1;
+ mpv_set_property(m_mpv, "ao-mute", MPV_FORMAT_FLAG, &value);
}
#include "libmpv_part.moc" \ No newline at end of file
diff --git a/kaffeine/src/player-parts/libmpv-part/libmpv_part.h b/kaffeine/src/player-parts/libmpv-part/libmpv_part.h
index cb771f5..e81429f 100644
--- a/kaffeine/src/player-parts/libmpv-part/libmpv_part.h
+++ b/kaffeine/src/player-parts/libmpv-part/libmpv_part.h
@@ -62,6 +62,7 @@ class MpvPart : public KaffeinePart
uint position() const; /* percent */
bool isPlaying();
bool isPaused();
+ bool isMute();
bool closeURL();
static TDEAboutData* createAboutData();
@@ -92,6 +93,10 @@ class MpvPart : public KaffeinePart
void slotStopSeeking();
void slotSetSeekingPos(int pos);
+ // Overloaded method with "int" argument
+ // Used in connection with m_volume::sliderMoved(int)
+ void slotSetVolume(int vol) { slotSetVolume(static_cast<uint>(vol)); }
+
private:
bool initMpv();
void initActions();
@@ -102,6 +107,7 @@ class MpvPart : public KaffeinePart
TQWidget *m_player;
MpvEventThread *m_eventThread;
TQSlider *m_position;
+ TQSlider *m_volume;
TQPushButton *m_playtime;
MRL m_mrl;
diff --git a/kaffeine/src/player-parts/libmpv-part/libmpv_part.rc b/kaffeine/src/player-parts/libmpv-part/libmpv_part.rc
index 21e765c..9373445 100644
--- a/kaffeine/src/player-parts/libmpv-part/libmpv_part.rc
+++ b/kaffeine/src/player-parts/libmpv-part/libmpv_part.rc
@@ -10,7 +10,7 @@
<Action name="player_next"/>
</Menu>
</MenuBar>
-<ToolBar name="controls" position="Bottom"><text>Controls Toolbar</text>
+<ToolBar name="controls" position="Bottom"><text>Playback Controls Toolbar</text>
<Action name="player_previous"/>
<Action name="player_play"/>
<Action name="player_pause"/>
@@ -22,5 +22,9 @@
<Separator/>
<Action name="player_playtime"/>
</ToolBar>
-<StatusBar/>
+<ToolBar name="volume" fullWidth="false" position="Bottom"><text>Volume Controls Toolbar</text>
+ <Action name="player_mute"/>
+ <Action name="player_volume"/>
+ <Separator/>
+</ToolBar>
</kpartgui> \ No newline at end of file