mpvpart: added volume controls

Signed-off-by: Mavridis Philippe <mavridisf@gmail.com>
feat/libmpv-backend
Mavridis Philippe 1 year ago
parent 54545a0913
commit aee45d0509
No known key found for this signature in database
GPG Key ID: 93F66F98F906147D

@ -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"

@ -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;

@ -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>
Loading…
Cancel
Save