Skip to content

Commit

Permalink
service/mpris: reset position timestamps on seek
Browse files Browse the repository at this point in the history
Moving the onPositionUpdated callback to a bpPosition binding caused
it not to fire when Position was changed to the same value, which can
happen when quickly changing tracks before the player has sent a new
position.

This reverts the above change while still updating position on seek.
  • Loading branch information
outfoxxed committed Jan 5, 2025
1 parent fca058e commit 761d99d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/services/mpris/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ void MprisPlayer::setPosition(qreal position) {
this->player->Seek(target - pos);
}

this->bpPosition = target;
this->setPosition(target);
}

void MprisPlayer::onPositionUpdated() {
Expand All @@ -248,11 +248,16 @@ void MprisPlayer::onPositionUpdated() {
if (firstChange) emit this->positionSupportedChanged();
}

void MprisPlayer::setPosition(qlonglong position) {
this->bpPosition = position;
this->onPositionUpdated();
}

void MprisPlayer::onExportedPositionChanged() {
if (!this->lengthSupported()) emit this->lengthChanged();
}

void MprisPlayer::onSeek(qlonglong time) { this->bpPosition = time; }
void MprisPlayer::onSeek(qlonglong time) { this->setPosition(time); }

qreal MprisPlayer::length() const {
if (this->bInternalLength == -1) {
Expand Down
6 changes: 3 additions & 3 deletions src/services/mpris/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,8 @@ private slots:
private:
void onMetadataChanged();
void onPositionUpdated();
// call instead of setting bpPosition
void setPosition(qlonglong position);
void requestPositionUpdate() { this->pPosition.requestUpdate(); };

// clang-format off
Expand Down Expand Up @@ -457,7 +459,7 @@ private slots:
QS_DBUS_PROPERTY_BINDING(MprisPlayer, pCanSeek, bpCanSeek, playerProperties, "CanSeek");
QS_DBUS_PROPERTY_BINDING(MprisPlayer, pCanGoNext, bpCanGoNext, playerProperties, "CanGoNext");
QS_DBUS_PROPERTY_BINDING(MprisPlayer, pCanGoPrevious, bpCanGoPrevious, playerProperties, "CanGoPrevious");
QS_DBUS_PROPERTY_BINDING(MprisPlayer, qlonglong, pPosition, bpPosition, playerProperties, "Position", false);
QS_DBUS_PROPERTY_BINDING(MprisPlayer, qlonglong, pPosition, bpPosition, onPositionUpdated, playerProperties, "Position", false);
QS_DBUS_PROPERTY_BINDING(MprisPlayer, pVolume, bVolume, playerProperties, "Volume", false);
QS_DBUS_PROPERTY_BINDING(MprisPlayer, pMetadata, bpMetadata, playerProperties, "Metadata");
QS_DBUS_PROPERTY_BINDING(MprisPlayer, pPlaybackStatus, bpPlaybackStatus, playerProperties, "PlaybackStatus");
Expand All @@ -466,8 +468,6 @@ private slots:
QS_DBUS_PROPERTY_BINDING(MprisPlayer, pMinRate, bMinRate, playerProperties, "MinimumRate", false);
QS_DBUS_PROPERTY_BINDING(MprisPlayer, pMaxRate, bMaxRate, playerProperties, "MaximumRate", false);
QS_DBUS_PROPERTY_BINDING(MprisPlayer, pShuffle, bShuffle, playerProperties, "Shuffle", false);

QS_BINDING_SUBSCRIBE_METHOD(MprisPlayer, bpPosition, onPositionUpdated, onValueChanged);
// clang-format on

QDateTime lastPositionTimestamp;
Expand Down

0 comments on commit 761d99d

Please sign in to comment.