Do some additional checks on entry before loading in AudioManager

This commit is contained in:
Bart De Vries 2021-04-29 11:10:09 +02:00
parent 943b66207b
commit 36ad248e55
1 changed files with 10 additions and 2 deletions

View File

@ -96,7 +96,10 @@ QUrl AudioManager::source() const
QMediaPlayer::Error AudioManager::error() const QMediaPlayer::Error AudioManager::error() const
{ {
if (d->m_player.error() != QMediaPlayer::NoError) { if (d->m_player.error() != QMediaPlayer::NoError) {
//qDebug() << "AudioManager::error" << d->m_player.errorString(); qDebug() << "AudioManager::error" << d->m_player.errorString();
// Some error occured: probably best to unset the lastPlayingEntry to
// avoid a deadlock when starting up again.
DataManager::instance().setLastPlayingEntry(QStringLiteral("none"));
} }
return d->m_player.error(); return d->m_player.error();
@ -165,6 +168,7 @@ QMediaPlayer::MediaStatus AudioManager::status() const
void AudioManager::setEntry(Entry* entry) void AudioManager::setEntry(Entry* entry)
{ {
d->m_lockPositionSaving = true; d->m_lockPositionSaving = true;
// 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 (d->m_entry) {
@ -179,7 +183,11 @@ void AudioManager::setEntry(Entry* entry)
d->m_entry->setQueueStatus(false); // i.e. remove from queue TODO: make this a choice in settings d->m_entry->setQueueStatus(false); // i.e. remove from queue TODO: make this a choice in settings
} }
} }
if (entry != nullptr) {
//qDebug() << entry->hasEnclosure() << entry->enclosure() << entry->enclosure()->status();
// do some checks on the new entry to see whether it's valid and not corrupted
if (entry != nullptr && entry->hasEnclosure() && entry->enclosure() && entry->enclosure()->status() == Enclosure::Downloaded) {
//qDebug() << "Going to change source"; //qDebug() << "Going to change source";
d->m_entry = entry; d->m_entry = entry;
Q_EMIT entryChanged(entry); Q_EMIT entryChanged(entry);