Solve issues with playback signals firing while changing tracks

This commit is contained in:
Bart De Vries 2023-02-20 11:34:49 +01:00
parent cbf586d518
commit e6fee85f4e
1 changed files with 15 additions and 10 deletions

View File

@ -248,15 +248,15 @@ void AudioManager::setCurrentBackend(KMediaSession::MediaBackends backend)
void AudioManager::setEntry(Entry *entry) void AudioManager::setEntry(Entry *entry)
{ {
// First unset current track, such that any signal that fires doesn't // First unset current track and save playing state, such that any signal
// operate on the wrong track // that still 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 and lock position saving
d->m_pendingSeek = -1; d->m_pendingSeek = -1;
d->m_lockPositionSaving = true; d->m_lockPositionSaving = true;
// d->m_player.setNotifyInterval(1000);
Entry *oldEntry = d->m_entry;
d->m_entry = nullptr;
// 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
@ -269,7 +269,12 @@ void AudioManager::setEntry(Entry *entry)
qCDebug(kastsAudio) << "Mark as read:" << oldEntry->title(); qCDebug(kastsAudio) << "Mark as read:" << oldEntry->title();
oldEntry->enclosure()->setPlayPosition(0); oldEntry->enclosure()->setPlayPosition(0);
oldEntry->setRead(true); oldEntry->setRead(true);
stop();
d->m_continuePlayback = SettingsManager::self()->continuePlayingNextEntry(); d->m_continuePlayback = SettingsManager::self()->continuePlayingNextEntry();
} else {
bool continuePlaying = d->m_continuePlayback; // saving to local bool because it will be overwritten by the stop action
stop();
d->m_continuePlayback = continuePlaying;
} }
} }
@ -279,23 +284,23 @@ void AudioManager::setEntry(Entry *entry)
|| (d->m_networkStatus.connectivity() != SolidExtras::NetworkStatus::No || (d->m_networkStatus.connectivity() != SolidExtras::NetworkStatus::No
&& (d->m_networkStatus.metered() != SolidExtras::NetworkStatus::Yes || SettingsManager::self()->allowMeteredStreaming())))) { && (d->m_networkStatus.metered() != SolidExtras::NetworkStatus::Yes || SettingsManager::self()->allowMeteredStreaming())))) {
qCDebug(kastsAudio) << "Going to change source"; qCDebug(kastsAudio) << "Going to change source";
d->m_entry = entry;
Q_EMIT entryChanged(entry);
QUrl loadUrl; QUrl loadUrl;
if (entry->enclosure()->status() == Enclosure::Downloaded) { if (entry->enclosure()->status() == Enclosure::Downloaded) {
loadUrl = QUrl::fromLocalFile(d->m_entry->enclosure()->path()); loadUrl = QUrl::fromLocalFile(entry->enclosure()->path());
if (d->m_isStreaming) { if (d->m_isStreaming) {
d->m_isStreaming = false; d->m_isStreaming = false;
Q_EMIT isStreamingChanged(); Q_EMIT isStreamingChanged();
} }
} else { } else {
loadUrl = QUrl(d->m_entry->enclosure()->url()); loadUrl = QUrl(entry->enclosure()->url());
if (!d->m_isStreaming) { if (!d->m_isStreaming) {
d->m_isStreaming = true; d->m_isStreaming = true;
Q_EMIT isStreamingChanged(); Q_EMIT isStreamingChanged();
} }
} }
d->m_entry = entry;
Q_EMIT entryChanged(entry);
d->m_player.setSource(loadUrl); d->m_player.setSource(loadUrl);
// save the current playing track in the settingsfile for restoring on startup // save the current playing track in the settingsfile for restoring on startup