Fix recursive loop when last track finishes playing

This commit is contained in:
Bart De Vries 2021-07-06 19:21:57 +02:00
parent f9287e94f8
commit 73b2cf565c
1 changed files with 10 additions and 5 deletions

View File

@ -196,6 +196,11 @@ QMediaPlayer::MediaStatus AudioManager::status() const
void AudioManager::setEntry(Entry *entry) void AudioManager::setEntry(Entry *entry)
{ {
// First unset current track, such that any signal that fires doesn't
// operate on the wrong track
Entry *oldEntry = d->m_entry;
d->m_entry = nullptr;
// reset any pending seek action, lock position saving and notify interval // reset any pending seek action, lock position saving and notify interval
d->m_pendingSeek = -1; d->m_pendingSeek = -1;
d->m_lockPositionSaving = true; d->m_lockPositionSaving = true;
@ -203,15 +208,15 @@ void AudioManager::setEntry(Entry *entry)
// First check if the previous track needs to be marked as read // First check if the previous track needs to be marked as read
// TODO: make grace time a setting in SettingsManager // TODO: make grace time a setting in SettingsManager
if (d->m_entry) { if (oldEntry) {
qCDebug(kastsAudio) << "Checking previous track"; qCDebug(kastsAudio) << "Checking previous track";
qCDebug(kastsAudio) << "Left time" << (duration() - position()); qCDebug(kastsAudio) << "Left time" << (duration() - position());
qCDebug(kastsAudio) << "MediaStatus" << d->m_player.mediaStatus(); qCDebug(kastsAudio) << "MediaStatus" << d->m_player.mediaStatus();
if (((duration() > 0) && (position() > 0) && ((duration() - position()) < SKIP_TRACK_END)) || (d->m_player.mediaStatus() == QMediaPlayer::EndOfMedia)) { if (((duration() > 0) && (position() > 0) && ((duration() - position()) < SKIP_TRACK_END)) || (d->m_player.mediaStatus() == QMediaPlayer::EndOfMedia)) {
qCDebug(kastsAudio) << "Mark as read:" << d->m_entry->title(); qCDebug(kastsAudio) << "Mark as read:" << oldEntry->title();
d->m_entry->setRead(true); oldEntry->setRead(true);
d->m_entry->enclosure()->setPlayPosition(0); oldEntry->enclosure()->setPlayPosition(0);
d->m_entry->setQueueStatus(false); // i.e. remove from queue TODO: make this a choice in settings oldEntry->setQueueStatus(false); // i.e. remove from queue TODO: make this a choice in settings
d->m_continuePlayback = SettingsManager::self()->continuePlayingNextEntry(); d->m_continuePlayback = SettingsManager::self()->continuePlayingNextEntry();
} }
} }