[app/mpris] Support non-seekable players
This commit is contained in:
parent
4c95bbdc21
commit
749dcfa148
8 changed files with 84 additions and 32 deletions
58
app/qml/MprisSlider.qml
Normal file
58
app/qml/MprisSlider.qml
Normal file
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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))
|
||||
}
|
||||
|
|
|
@ -10,5 +10,6 @@
|
|||
<file>qml/FindDevicesPage.qml</file>
|
||||
<file>qml/runcommand.qml</file>
|
||||
<file>qml/volume.qml</file>
|
||||
<file>qml/MprisSlider.qml</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<bool>(QStringLiteral("isPlaying"), m_playing);
|
||||
m_canSeek = np.get<bool>(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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue