From 71ac94a831d65d12a51355717e0a95644927d9ca Mon Sep 17 00:00:00 2001 From: Bart De Vries Date: Thu, 25 Apr 2024 13:44:31 +0200 Subject: [PATCH] Workaround for a qtmultimedia backend issue Qt multimedia with the ffmpeg backend suddenly started sending LoadedMedia signals in the PlayingState, even though that should not be a valid combination according to the docs. This is messing up the AudioManager. --- src/audiomanager.cpp | 9 ++++++++- src/kmediasession/mediabackends/qtmediabackend.cpp | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/audiomanager.cpp b/src/audiomanager.cpp index 16386cde..e1cb33a6 100644 --- a/src/audiomanager.cpp +++ b/src/audiomanager.cpp @@ -699,8 +699,15 @@ void AudioManager::checkForPendingSeek() qCDebug(kastsAudio) << "Seek pending?" << d->m_pendingSeek; qCDebug(kastsAudio) << "Current position" << position; + // FIXME: the LoadedMedia+PlayingState test is a workaround for a broken + // qtmultimedia backend; LoadedMedia should never be allowed in the + // PlayingState according to docs. Remove this when upstream is fixed. + // Check if we're supposed to skip to a new position - if (d->m_pendingSeek != -1 && d->m_player.mediaStatus() == KMediaSession::BufferedMedia && d->m_player.duration() > 0) { + if (d->m_pendingSeek != -1 + && (d->m_player.mediaStatus() == KMediaSession::BufferedMedia + || (d->m_player.mediaStatus() == KMediaSession::LoadedMedia && d->m_player.playbackState() == KMediaSession::PlayingState)) + && d->m_player.duration() > 0) { if (abs(d->m_pendingSeek - position) > 2000) { qCDebug(kastsAudio) << "Position seek still pending to position" << d->m_pendingSeek; qCDebug(kastsAudio) << "Current reported position and duration" << d->m_player.position() << d->m_player.duration(); diff --git a/src/kmediasession/mediabackends/qtmediabackend.cpp b/src/kmediasession/mediabackends/qtmediabackend.cpp index 54225f51..5b1bd4ff 100644 --- a/src/kmediasession/mediabackends/qtmediabackend.cpp +++ b/src/kmediasession/mediabackends/qtmediabackend.cpp @@ -321,7 +321,7 @@ KMediaSession::MediaStatus QtMediaBackendPrivate::translateMediaStatusEnum(QMedi KMediaSession::PlaybackState QtMediaBackendPrivate::translatePlaybackStateEnum(QMediaPlayer::PlaybackState playbackStateEnum) { - qCDebug(QtMediaBackendLog) << "QtMediaBackendPrivate::translateMediaStatusEnum(" << playbackStateEnum << ")"; + qCDebug(QtMediaBackendLog) << "QtMediaBackendPrivate::translatePlaybackStateEnum(" << playbackStateEnum << ")"; switch (playbackStateEnum) { case QMediaPlayer::PlaybackState::StoppedState: