forked from quickshell/quickshell
service/mpris: improve compatibility with noncompliant players
This commit is contained in:
parent
5016dbf0d4
commit
06240ccf80
|
@ -192,15 +192,15 @@ void MprisPlayer::setPosition(qreal position) {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto target = static_cast<qlonglong>(position * 1000) * 1000;
|
auto target = static_cast<qlonglong>(position * 1000) * 1000;
|
||||||
this->pPosition.set(target);
|
|
||||||
|
|
||||||
if (!this->mTrackId.isEmpty()) {
|
if (!this->mTrackId.isEmpty()) {
|
||||||
this->player->SetPosition(QDBusObjectPath(this->mTrackId), target);
|
this->player->SetPosition(QDBusObjectPath(this->mTrackId), target);
|
||||||
return;
|
|
||||||
} else {
|
} else {
|
||||||
auto pos = this->positionMs() * 1000;
|
auto pos = this->positionMs() * 1000;
|
||||||
this->player->Seek(target - pos);
|
this->player->Seek(target - pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->pPosition.set(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MprisPlayer::onPositionChanged() {
|
void MprisPlayer::onPositionChanged() {
|
||||||
|
@ -247,6 +247,8 @@ void MprisPlayer::setVolume(qreal volume) {
|
||||||
QVariantMap MprisPlayer::metadata() const { return this->pMetadata.get(); }
|
QVariantMap MprisPlayer::metadata() const { return this->pMetadata.get(); }
|
||||||
|
|
||||||
void MprisPlayer::onMetadataChanged() {
|
void MprisPlayer::onMetadataChanged() {
|
||||||
|
emit this->metadataChanged();
|
||||||
|
|
||||||
auto lengthVariant = this->pMetadata.get().value("mpris:length");
|
auto lengthVariant = this->pMetadata.get().value("mpris:length");
|
||||||
qlonglong length = -1;
|
qlonglong length = -1;
|
||||||
if (lengthVariant.isValid() && lengthVariant.canConvert<qlonglong>()) {
|
if (lengthVariant.isValid() && lengthVariant.canConvert<qlonglong>()) {
|
||||||
|
@ -258,20 +260,34 @@ void MprisPlayer::onMetadataChanged() {
|
||||||
emit this->lengthChanged();
|
emit this->lengthChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto trackChanged = false;
|
||||||
|
|
||||||
auto trackidVariant = this->pMetadata.get().value("mpris:trackid");
|
auto trackidVariant = this->pMetadata.get().value("mpris:trackid");
|
||||||
if (trackidVariant.isValid() && trackidVariant.canConvert<QString>()) {
|
if (trackidVariant.isValid() && trackidVariant.canConvert<QString>()) {
|
||||||
auto trackId = trackidVariant.value<QString>();
|
auto trackId = trackidVariant.value<QString>();
|
||||||
|
|
||||||
if (trackId != this->mTrackId) {
|
if (trackId != this->mTrackId) {
|
||||||
this->mTrackId = trackId;
|
this->mTrackId = trackId;
|
||||||
emit this->trackChanged();
|
trackChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Some players don't seem to send position updats or seeks on track change.
|
|
||||||
this->pPosition.update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
emit this->metadataChanged();
|
// Helps to catch players without trackid.
|
||||||
|
auto urlVariant = this->pMetadata.get().value("xesam:url");
|
||||||
|
if (urlVariant.isValid() && urlVariant.canConvert<QString>()) {
|
||||||
|
auto url = urlVariant.value<QString>();
|
||||||
|
|
||||||
|
if (url != this->mUrl) {
|
||||||
|
this->mUrl = url;
|
||||||
|
trackChanged = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (trackChanged) {
|
||||||
|
// Some players don't seem to send position updates or seeks on track change.
|
||||||
|
this->pPosition.update();
|
||||||
|
emit this->trackChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MprisPlaybackState::Enum MprisPlayer::playbackState() const { return this->mPlaybackState; }
|
MprisPlaybackState::Enum MprisPlayer::playbackState() const { return this->mPlaybackState; }
|
||||||
|
|
|
@ -326,6 +326,7 @@ private:
|
||||||
DBusMprisPlayerApp* app = nullptr;
|
DBusMprisPlayerApp* app = nullptr;
|
||||||
DBusMprisPlayer* player = nullptr;
|
DBusMprisPlayer* player = nullptr;
|
||||||
QString mTrackId;
|
QString mTrackId;
|
||||||
|
QString mUrl;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace qs::service::mpris
|
} // namespace qs::service::mpris
|
||||||
|
|
Loading…
Reference in a new issue