Commit 1ce07b1c authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇

Also handle muted property on player

Report a Volume of 0.0 for a muted player and set its muted property to whether volume is 0.0

Differential Revision: https://phabricator.kde.org/D20925
parent 1aa61cb9
......@@ -256,6 +256,7 @@ addCallback("mpris", "setPlaybackRate", function (message) {
addCallback("mpris", "setVolume", function (message) {
if (activePlayer) {
activePlayer.volume = message.volume;
activePlayer.muted = (message.volume == 0.0);
}
});
......@@ -315,6 +316,7 @@ function setPlayerActive(player) {
currentTime: player.currentTime,
playbackRate: player.playbackRate,
volume: player.volume,
muted: player.muted,
loop: player.loop,
metadata: playerMetadata,
callbacks: playerCallbacks
......@@ -434,7 +436,8 @@ function registerPlayer(player) {
player.addEventListener("volumechange", function () {
sendPlayerInfo(player, "volumechange", {
volume: player.volume
volume: player.volume,
muted: player.muted
});
});
......
......@@ -135,6 +135,7 @@ void MPrisPlugin::handleData(const QString &event, const QJsonObject &data)
m_artist.clear();
m_artworkUrl.clear();
m_volume = 1.0;
m_muted = false;
m_length = 0;
m_position = 0;
} else if (event == QLatin1String("playing")) {
......@@ -143,9 +144,12 @@ void MPrisPlugin::handleData(const QString &event, const QJsonObject &data)
m_url = QUrl(data.value(QStringLiteral("url")).toString());
m_mediaSrc = QUrl(data.value(QStringLiteral("mediaSrc")).toString());
const qreal volume = data.value(QStringLiteral("volume")).toDouble(1);
if (m_volume != volume) {
m_volume = volume;
const qreal oldVolume = volume();
m_volume = data.value(QStringLiteral("volume")).toDouble(1);
m_muted = data.value(QStringLiteral("muted")).toBool();
if (volume() != oldVolume) {
emitPropertyChange(m_player, "Volume");
}
......@@ -208,6 +212,7 @@ void MPrisPlugin::handleData(const QString &event, const QJsonObject &data)
setPosition(position * 1000 * 1000);
} else if (event == QLatin1String("volumechange")) {
m_volume = data.value(QStringLiteral("volume")).toDouble(1);
m_muted = data.value(QStringLiteral("muted")).toBool();
emitPropertyChange(m_player, "Volume");
} else if (event == QLatin1String("metadata")) {
processMetadata(data.value(QStringLiteral("metadata")).toObject());
......@@ -294,6 +299,9 @@ bool MPrisPlugin::canSeek() const
qreal MPrisPlugin::volume() const
{
if (m_muted) {
return 0.0;
}
return m_volume;
}
......
......@@ -158,6 +158,7 @@ private:
QUrl m_artworkUrl;
qreal m_volume = 1.0;
bool m_muted = false;
qlonglong m_length = 0;
qlonglong m_position = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment