From 6326f60ce23c9c95494cbbe0511d42f15e12d736 Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Thu, 23 May 2024 02:38:26 -0700 Subject: [PATCH] service/mpris: re-query position on playback and metadata change --- src/services/mpris/player.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/services/mpris/player.cpp b/src/services/mpris/player.cpp index 27ba34c..e17f3e8 100644 --- a/src/services/mpris/player.cpp +++ b/src/services/mpris/player.cpp @@ -267,7 +267,8 @@ void MprisPlayer::onMetadataChanged() { emit this->trackChanged(); } - this->onSeek(0); + // Some players don't seem to send position updats or seeks on track change. + this->pPosition.update(); } emit this->metadataChanged(); @@ -313,21 +314,25 @@ void MprisPlayer::setPlaybackState(MprisPlaybackState::Enum playbackState) { void MprisPlayer::onPlaybackStatusChanged() { const auto& status = this->pPlaybackStatus.get(); + auto state = MprisPlaybackState::Stopped; if (status == "Playing") { - // update the timestamp - this->onSeek(this->positionMs() * 1000); - this->mPlaybackState = MprisPlaybackState::Playing; + state = MprisPlaybackState::Playing; } else if (status == "Paused") { this->pausedTime = QDateTime::currentDateTimeUtc(); - this->mPlaybackState = MprisPlaybackState::Paused; + state = MprisPlaybackState::Paused; } else if (status == "Stopped") { - this->mPlaybackState = MprisPlaybackState::Stopped; + state = MprisPlaybackState::Stopped; } else { - this->mPlaybackState = MprisPlaybackState::Stopped; + state = MprisPlaybackState::Stopped; qWarning() << "Received unexpected PlaybackStatus for" << this << status; } - emit this->playbackStateChanged(); + if (state != this->mPlaybackState) { + // make sure we're in sync at least on play/pause. Some players don't automatically send this. + this->pPosition.update(); + this->mPlaybackState = state; + emit this->playbackStateChanged(); + } } MprisLoopState::Enum MprisPlayer::loopState() const { return this->mLoopState; }