Restart the sound device if it's been stopped (#4549)

Fixes a bug where we don't check if the sound device is active before trying to play a sound to it

We fix this by checking its state before every sound we try to play, and if the device is not in the started state we try to restart it.
This commit is contained in:
pajlada
2023-04-16 13:16:12 +02:00
committed by GitHub
parent d6ef48d4ef
commit 8124ab439c
2 changed files with 21 additions and 0 deletions
+20
View File
@@ -190,6 +190,26 @@ void SoundController::play(const QUrl &sound)
return;
}
auto deviceState = ma_device_get_state(this->device.get());
if (deviceState != ma_device_state_started)
{
// Device state is not as it should be, try to restart it
qCWarning(chatterinoSound)
<< "Sound device was not started, attempting to restart it"
<< deviceState;
auto result = ma_device_start(this->device.get());
if (result != MA_SUCCESS)
{
qCWarning(chatterinoSound)
<< "Failed to start the sound device" << result;
return;
}
qCInfo(chatterinoSound) << "Successfully restarted the sound device";
}
if (sound.isLocalFile())
{
auto soundPath = sound.toLocalFile();