mpris2: Fix mpris:trackid type with Plasma 6

This commit is contained in:
Reverier-Xu 2024-03-13 19:11:48 +08:00 committed by Jonas Kvinge
parent 2ccb0af75e
commit 88b5cf2461
3 changed files with 9 additions and 4 deletions

View File

@ -379,8 +379,8 @@ void Mpris2::SetRating(double rating) {
} }
QString Mpris2::current_track_id() const { QDBusObjectPath Mpris2::current_track_id() const {
return QString("/org/strawberrymusicplayer/strawberry/Track/%1").arg(QString::number(app_->playlist_manager()->active()->current_row())); return QDBusObjectPath(QString("/org/strawberrymusicplayer/strawberry/Track/%1").arg(QString::number(app_->playlist_manager()->active()->current_row())));
} }
// We send Metadata change notification as soon as the process of changing song starts... // We send Metadata change notification as soon as the process of changing song starts...
@ -512,7 +512,7 @@ void Mpris2::Seek(qint64 offset) {
void Mpris2::SetPosition(const QDBusObjectPath &trackId, qint64 offset) { void Mpris2::SetPosition(const QDBusObjectPath &trackId, qint64 offset) {
if (CanSeek() && trackId.path() == current_track_id() && offset >= 0) { if (CanSeek() && trackId == current_track_id() && offset >= 0) {
offset *= kNsecPerUsec; offset *= kNsecPerUsec;
if (offset < app_->player()->GetCurrentItem()->Metadata().length_nanosec()) { if (offset < app_->player()->GetCurrentItem()->Metadata().length_nanosec()) {

View File

@ -225,7 +225,7 @@ class Mpris2 : public QObject {
QString PlaybackStatus(EngineBase::State state) const; QString PlaybackStatus(EngineBase::State state) const;
QString current_track_id() const; QDBusObjectPath current_track_id() const;
bool CanSeek(EngineBase::State state) const; bool CanSeek(EngineBase::State state) const;

View File

@ -28,6 +28,7 @@
#include <QDateTime> #include <QDateTime>
#include <QString> #include <QString>
#include <QStringList> #include <QStringList>
#include <QDBusObjectPath>
namespace mpris { namespace mpris {
@ -55,6 +56,10 @@ inline void AddMetadata(const QString &key, const QDateTime &metadata, QVariantM
if (metadata.isValid()) (*map)[key] = metadata; if (metadata.isValid()) (*map)[key] = metadata;
} }
inline void AddMetadata(const QString &key, const QDBusObjectPath &metadata, QVariantMap *map) {
if (metadata.path().length() > 0) (*map)[key] = metadata;
}
inline QString AsMPRISDateTimeType(const qint64 time) { inline QString AsMPRISDateTimeType(const qint64 time) {
return time != -1 ? QDateTime::fromSecsSinceEpoch(time).toString(Qt::ISODate) : ""; return time != -1 ? QDateTime::fromSecsSinceEpoch(time).toString(Qt::ISODate) : "";
} }