[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
|
id: root
|
||||||
property QtObject pluginInterface
|
property QtObject pluginInterface
|
||||||
property bool muted: false
|
property bool muted: false
|
||||||
property bool updatePositionSlider: true
|
|
||||||
property int volumeUnmuted
|
property int volumeUnmuted
|
||||||
property var volume: pluginInterface.volume
|
property var volume: pluginInterface.volume
|
||||||
property var lastPosition: pluginInterface.position
|
|
||||||
property date lastPositionTime: new Date()
|
|
||||||
title: i18n("Multimedia Controls")
|
title: i18n("Multimedia Controls")
|
||||||
|
|
||||||
onLastPositionChanged: {
|
|
||||||
lastPositionTime = new Date();
|
|
||||||
}
|
|
||||||
|
|
||||||
onVolumeChanged: {
|
onVolumeChanged: {
|
||||||
if (muted && volume != 0) {
|
if (muted && volume != 0) {
|
||||||
toggleMute()
|
toggleMute()
|
||||||
|
@ -78,11 +71,6 @@ Kirigami.Page
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Connections {
|
|
||||||
target: root.pluginInterface
|
|
||||||
onNowPlayingChanged: positionSlider.value = lastPosition
|
|
||||||
}
|
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
id: noPlayersText
|
id: noPlayersText
|
||||||
text: i18n("No players available")
|
text: i18n("No players available")
|
||||||
|
@ -158,29 +146,15 @@ Kirigami.Page
|
||||||
RowLayout {
|
RowLayout {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Label {
|
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())
|
MprisSlider {
|
||||||
}
|
id: positionIndicator
|
||||||
onPressedChanged: {
|
plugin: root.pluginInterface
|
||||||
if (pressed) {
|
Layout.fillWidth: true
|
||||||
updatePositionSlider = false
|
|
||||||
} else {
|
|
||||||
updatePositionSlider = true
|
|
||||||
root.pluginInterface.position = value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
text: msToTime(new Date(root.pluginInterface.length), new Date(root.pluginInterface.length))
|
text: msToTime(new Date(root.pluginInterface.length), new Date(root.pluginInterface.length))
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,5 +10,6 @@
|
||||||
<file>qml/FindDevicesPage.qml</file>
|
<file>qml/FindDevicesPage.qml</file>
|
||||||
<file>qml/runcommand.qml</file>
|
<file>qml/runcommand.qml</file>
|
||||||
<file>qml/volume.qml</file>
|
<file>qml/volume.qml</file>
|
||||||
|
<file>qml/MprisSlider.qml</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
|
@ -152,6 +152,7 @@ class KDECONNECTINTERFACES_EXPORT MprisDbusInterface
|
||||||
Q_PROPERTY(QStringList playerList READ playerList NOTIFY propertiesChangedProxy)
|
Q_PROPERTY(QStringList playerList READ playerList NOTIFY propertiesChangedProxy)
|
||||||
Q_PROPERTY(int volume READ volume WRITE setVolume NOTIFY propertiesChangedProxy)
|
Q_PROPERTY(int volume READ volume WRITE setVolume NOTIFY propertiesChangedProxy)
|
||||||
Q_PROPERTY(int position READ position WRITE setPosition NOTIFY propertiesChangedProxy)
|
Q_PROPERTY(int position READ position WRITE setPosition NOTIFY propertiesChangedProxy)
|
||||||
|
Q_PROPERTY(bool canSeek READ canSeek NOTIFY propertiesChangedProxy)
|
||||||
public:
|
public:
|
||||||
explicit MprisDbusInterface(const QString& deviceId, QObject* parent = nullptr);
|
explicit MprisDbusInterface(const QString& deviceId, QObject* parent = nullptr);
|
||||||
~MprisDbusInterface() override;
|
~MprisDbusInterface() override;
|
||||||
|
|
|
@ -34,6 +34,7 @@ MprisRemotePlayer::MprisRemotePlayer() :
|
||||||
, m_title()
|
, m_title()
|
||||||
, m_artist()
|
, m_artist()
|
||||||
, m_album()
|
, m_album()
|
||||||
|
, m_canSeek(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,6 +55,8 @@ void MprisRemotePlayer::parseNetworkPacket(const NetworkPacket& np)
|
||||||
m_lastPositionTime = QDateTime::currentMSecsSinceEpoch();
|
m_lastPositionTime = QDateTime::currentMSecsSinceEpoch();
|
||||||
}
|
}
|
||||||
m_playing = np.get<bool>(QStringLiteral("isPlaying"), m_playing);
|
m_playing = np.get<bool>(QStringLiteral("isPlaying"), m_playing);
|
||||||
|
m_canSeek = np.get<bool>(QStringLiteral("canSeek"), m_canSeek);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
long MprisRemotePlayer::position() const
|
long MprisRemotePlayer::position() const
|
||||||
|
@ -105,3 +108,8 @@ QString MprisRemotePlayer::album() const
|
||||||
{
|
{
|
||||||
return m_album;
|
return m_album;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MprisRemotePlayer::canSeek() const
|
||||||
|
{
|
||||||
|
return m_canSeek;
|
||||||
|
}
|
||||||
|
|
|
@ -39,6 +39,7 @@ public:
|
||||||
QString title() const;
|
QString title() const;
|
||||||
QString artist() const;
|
QString artist() const;
|
||||||
QString album() const;
|
QString album() const;
|
||||||
|
bool canSeek() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -52,4 +53,5 @@ private:
|
||||||
QString m_title;
|
QString m_title;
|
||||||
QString m_artist;
|
QString m_artist;
|
||||||
QString m_album;
|
QString m_album;
|
||||||
|
bool m_canSeek;
|
||||||
};
|
};
|
||||||
|
|
|
@ -203,4 +203,10 @@ QString MprisRemotePlugin::artist() const
|
||||||
return player ? player->artist() : QString();
|
return player ? player->artist() : QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MprisRemotePlugin::canSeek() const
|
||||||
|
{
|
||||||
|
auto player = m_players.value(m_currentPlayer);
|
||||||
|
return player ? player->canSeek() : false;
|
||||||
|
}
|
||||||
|
|
||||||
#include "mprisremoteplugin.moc"
|
#include "mprisremoteplugin.moc"
|
||||||
|
|
|
@ -45,6 +45,7 @@ class Q_DECL_EXPORT MprisRemotePlugin
|
||||||
Q_PROPERTY(QString title READ title NOTIFY propertiesChanged)
|
Q_PROPERTY(QString title READ title NOTIFY propertiesChanged)
|
||||||
Q_PROPERTY(QString artist READ artist NOTIFY propertiesChanged)
|
Q_PROPERTY(QString artist READ artist NOTIFY propertiesChanged)
|
||||||
Q_PROPERTY(QString album READ album NOTIFY propertiesChanged)
|
Q_PROPERTY(QString album READ album NOTIFY propertiesChanged)
|
||||||
|
Q_PROPERTY(bool canSeek READ canSeek NOTIFY propertiesChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MprisRemotePlugin(QObject* parent, const QVariantList &args);
|
explicit MprisRemotePlugin(QObject* parent, const QVariantList &args);
|
||||||
|
@ -60,6 +61,7 @@ public:
|
||||||
QString title() const;
|
QString title() const;
|
||||||
QString artist() const;
|
QString artist() const;
|
||||||
QString album() const;
|
QString album() const;
|
||||||
|
bool canSeek() const;
|
||||||
|
|
||||||
void setVolume(int volume);
|
void setVolume(int volume);
|
||||||
void setPosition(int position);
|
void setPosition(int position);
|
||||||
|
|
Loading…
Reference in a new issue