Fix sounds on Qt6 (#5439)

This commit is contained in:
Zach H 2025-01-10 23:10:47 -05:00 committed by GitHub
parent 1a3df84f0a
commit 8bea3f8997
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 16 additions and 5 deletions

View file

@ -28,6 +28,10 @@ SoundEngine::~SoundEngine()
player->deleteLater();
player = nullptr;
}
if (audioOutput) {
audioOutput->deleteLater();
audioOutput = nullptr;
}
}
void SoundEngine::soundEnabledChanged()
@ -37,8 +41,8 @@ void SoundEngine::soundEnabledChanged()
if (!player) {
player = new QMediaPlayer;
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
auto qAudioOutput = new QAudioOutput;
player->setAudioOutput(qAudioOutput);
audioOutput = new QAudioOutput(player);
player->setAudioOutput(audioOutput);
#endif
}
} else {
@ -48,6 +52,10 @@ void SoundEngine::soundEnabledChanged()
player->deleteLater();
player = nullptr;
}
if (audioOutput) {
audioOutput->deleteLater();
audioOutput = nullptr;
}
}
}