diff --git a/app/qml/MprisSlider.qml b/app/qml/MprisSlider.qml
new file mode 100644
index 000000000..8c03a8b37
--- /dev/null
+++ b/app/qml/MprisSlider.qml
@@ -0,0 +1,58 @@
+import QtQuick 2.2
+import QtQuick.Controls 2.2
+
+Loader {
+
+ property var plugin
+ property var lastPosition: plugin.position
+ property date lastPositionTime: new Date()
+ property bool updatePositionSlider: true
+
+ sourceComponent: plugin.canSeek ? seekBar : progressBar
+
+ onLastPositionChanged: {
+ lastPositionTime = new Date();
+ }
+
+ Component {
+ id: seekBar
+
+ Slider {
+ from: 0
+ to: plugin.length
+ onPressedChanged: {
+ if (pressed) {
+ updatePositionSlider = false
+ } else {
+ updatePositionSlider = true
+ plugin.position = value
+ }
+ }
+ }
+ }
+
+ Component {
+ id: progressBar
+
+ ProgressBar {
+ from: 0
+ to: plugin.length
+ }
+ }
+
+ Timer {
+ id: positionUpdateTimer
+ interval: 1000
+ repeat: true
+ running: updatePositionSlider && plugin.isPlaying
+
+ onTriggered: item.value = lastPosition + (new Date().getTime() - lastPositionTime.getTime())
+ }
+
+ Connections {
+ target: plugin
+ onNowPlayingChanged: {
+ item.value = lastPosition
+ }
+ }
+}
diff --git a/app/qml/mpris.qml b/app/qml/mpris.qml
index fb432ecc3..ceb50c20a 100644
--- a/app/qml/mpris.qml
+++ b/app/qml/mpris.qml
@@ -28,17 +28,10 @@ Kirigami.Page
id: root
property QtObject pluginInterface
property bool muted: false
- property bool updatePositionSlider: true
property int volumeUnmuted
property var volume: pluginInterface.volume
- property var lastPosition: pluginInterface.position
- property date lastPositionTime: new Date()
title: i18n("Multimedia Controls")
- onLastPositionChanged: {
- lastPositionTime = new Date();
- }
-
onVolumeChanged: {
if (muted && volume != 0) {
toggleMute()
@@ -78,11 +71,6 @@ Kirigami.Page
}
}
- Connections {
- target: root.pluginInterface
- onNowPlayingChanged: positionSlider.value = lastPosition
- }
-
Label {
id: noPlayersText
text: i18n("No players available")
@@ -158,29 +146,15 @@ Kirigami.Page
RowLayout {
Layout.fillWidth: true
Label {
- text: msToTime(new Date(positionSlider.value), new Date(root.pluginInterface.length))
+ text: msToTime(new Date(positionIndicator.item.value), new Date(root.pluginInterface.length))
}
- Slider {
- id: positionSlider
- to: root.pluginInterface.length
- Layout.fillWidth: true
- Timer {
- id: positionUpdateTimer
- interval: 1000
- repeat: true
- running: updatePositionSlider && root.pluginInterface.isPlaying
- onTriggered: positionSlider.value = lastPosition + (new Date().getTime() - lastPositionTime.getTime())
- }
- onPressedChanged: {
- if (pressed) {
- updatePositionSlider = false
- } else {
- updatePositionSlider = true
- root.pluginInterface.position = value
- }
- }
+ MprisSlider {
+ id: positionIndicator
+ plugin: root.pluginInterface
+ Layout.fillWidth: true
}
+
Label {
text: msToTime(new Date(root.pluginInterface.length), new Date(root.pluginInterface.length))
}
diff --git a/app/resources.qrc b/app/resources.qrc
index ce3cfab40..e726a941d 100644
--- a/app/resources.qrc
+++ b/app/resources.qrc
@@ -10,5 +10,6 @@
qml/FindDevicesPage.qml
qml/runcommand.qml
qml/volume.qml
+ qml/MprisSlider.qml
diff --git a/interfaces/dbusinterfaces.h b/interfaces/dbusinterfaces.h
index 99ca6139c..e7007f71c 100644
--- a/interfaces/dbusinterfaces.h
+++ b/interfaces/dbusinterfaces.h
@@ -152,6 +152,7 @@ class KDECONNECTINTERFACES_EXPORT MprisDbusInterface
Q_PROPERTY(QStringList playerList READ playerList NOTIFY propertiesChangedProxy)
Q_PROPERTY(int volume READ volume WRITE setVolume NOTIFY propertiesChangedProxy)
Q_PROPERTY(int position READ position WRITE setPosition NOTIFY propertiesChangedProxy)
+ Q_PROPERTY(bool canSeek READ canSeek NOTIFY propertiesChangedProxy)
public:
explicit MprisDbusInterface(const QString& deviceId, QObject* parent = nullptr);
~MprisDbusInterface() override;
diff --git a/plugins/mprisremote/mprisremoteplayer.cpp b/plugins/mprisremote/mprisremoteplayer.cpp
index bbfa63886..8c93a68e5 100644
--- a/plugins/mprisremote/mprisremoteplayer.cpp
+++ b/plugins/mprisremote/mprisremoteplayer.cpp
@@ -34,6 +34,7 @@ MprisRemotePlayer::MprisRemotePlayer() :
, m_title()
, m_artist()
, m_album()
+ , m_canSeek(false)
{
}
@@ -54,6 +55,8 @@ void MprisRemotePlayer::parseNetworkPacket(const NetworkPacket& np)
m_lastPositionTime = QDateTime::currentMSecsSinceEpoch();
}
m_playing = np.get(QStringLiteral("isPlaying"), m_playing);
+ m_canSeek = np.get(QStringLiteral("canSeek"), m_canSeek);
+
}
long MprisRemotePlayer::position() const
@@ -105,3 +108,8 @@ QString MprisRemotePlayer::album() const
{
return m_album;
}
+
+bool MprisRemotePlayer::canSeek() const
+{
+ return m_canSeek;
+}
diff --git a/plugins/mprisremote/mprisremoteplayer.h b/plugins/mprisremote/mprisremoteplayer.h
index f9b5b4bf6..a83458d9b 100644
--- a/plugins/mprisremote/mprisremoteplayer.h
+++ b/plugins/mprisremote/mprisremoteplayer.h
@@ -39,6 +39,7 @@ public:
QString title() const;
QString artist() const;
QString album() const;
+ bool canSeek() const;
private:
@@ -52,4 +53,5 @@ private:
QString m_title;
QString m_artist;
QString m_album;
+ bool m_canSeek;
};
diff --git a/plugins/mprisremote/mprisremoteplugin.cpp b/plugins/mprisremote/mprisremoteplugin.cpp
index edb253952..22d6f7b3c 100644
--- a/plugins/mprisremote/mprisremoteplugin.cpp
+++ b/plugins/mprisremote/mprisremoteplugin.cpp
@@ -203,4 +203,10 @@ QString MprisRemotePlugin::artist() const
return player ? player->artist() : QString();
}
+bool MprisRemotePlugin::canSeek() const
+{
+ auto player = m_players.value(m_currentPlayer);
+ return player ? player->canSeek() : false;
+}
+
#include "mprisremoteplugin.moc"
diff --git a/plugins/mprisremote/mprisremoteplugin.h b/plugins/mprisremote/mprisremoteplugin.h
index aedfac79c..82629c28b 100644
--- a/plugins/mprisremote/mprisremoteplugin.h
+++ b/plugins/mprisremote/mprisremoteplugin.h
@@ -45,6 +45,7 @@ class Q_DECL_EXPORT MprisRemotePlugin
Q_PROPERTY(QString title READ title NOTIFY propertiesChanged)
Q_PROPERTY(QString artist READ artist NOTIFY propertiesChanged)
Q_PROPERTY(QString album READ album NOTIFY propertiesChanged)
+ Q_PROPERTY(bool canSeek READ canSeek NOTIFY propertiesChanged)
public:
explicit MprisRemotePlugin(QObject* parent, const QVariantList &args);
@@ -60,6 +61,7 @@ public:
QString title() const;
QString artist() const;
QString album() const;
+ bool canSeek() const;
void setVolume(int volume);
void setPosition(int position);