More elegant solution for setting MPRIS2 audio duration when changing tracks

This commit is contained in:
Bart De Vries 2021-04-14 20:23:48 +02:00
parent a624040ef3
commit 49baa7915b
2 changed files with 12 additions and 1 deletions

View File

@ -219,7 +219,6 @@ void AudioManager::setEntry(Entry* entry)
if (startingPosition > 1000) d->m_player.setPosition(startingPosition); if (startingPosition > 1000) d->m_player.setPosition(startingPosition);
d->m_player.pause(); d->m_player.pause();
d->m_readyToPlay = true; d->m_readyToPlay = true;
Q_EMIT entryChanged(d->m_entry); // TODO: this is a hack to get MPRIS to show correct duration; should be split off into a separate signal
Q_EMIT canPlayChanged(); Q_EMIT canPlayChanged();
Q_EMIT canPauseChanged(); Q_EMIT canPauseChanged();
Q_EMIT canSkipForwardChanged(); Q_EMIT canSkipForwardChanged();

View File

@ -280,6 +280,18 @@ void MediaPlayer2Player::audioPositionChanged()
void MediaPlayer2Player::audioDurationChanged() void MediaPlayer2Player::audioDurationChanged()
{ {
qDebug() << "Signal change of audio duration through MPRIS2";
// We reset all metadata in case the audioDuration changed
// This is done because duration is not yet available when setEntry is
// called (this is before the QMediaPlayer has read the new track
if (m_audioPlayer) {
if (m_audioPlayer->entry()) {
m_metadata = getMetadataOfCurrentTrack();
signalPropertiesChange(QStringLiteral("Metadata"), Metadata());
}
}
// for progress indicator on taskbar
if (m_audioPlayer) { if (m_audioPlayer) {
setPropertyPosition(static_cast<int>(m_audioPlayer->position())); setPropertyPosition(static_cast<int>(m_audioPlayer->position()));
} }