Fixed an issue where the application would hang if there were no audio devices available.

This commit is contained in:
Leon Styhre 2020-12-31 14:27:31 +01:00
parent 9b6789529b
commit daf9b62936
3 changed files with 8 additions and 0 deletions

View file

@ -19,6 +19,7 @@ std::vector<std::shared_ptr<Sound>> AudioManager::sSoundVector;
SDL_AudioDeviceID AudioManager::sAudioDevice = 0; SDL_AudioDeviceID AudioManager::sAudioDevice = 0;
SDL_AudioSpec AudioManager::sAudioFormat; SDL_AudioSpec AudioManager::sAudioFormat;
SDL_AudioStream* AudioManager::sConversionStream; SDL_AudioStream* AudioManager::sConversionStream;
bool AudioManager::sHasAudioDevice = true;
AudioManager::AudioManager() AudioManager::AudioManager()
{ {
@ -75,6 +76,7 @@ void AudioManager::init()
if (sAudioDevice == 0) { if (sAudioDevice == 0) {
LOG(LogError) << "Unable to open audio device: " << SDL_GetError(); LOG(LogError) << "Unable to open audio device: " << SDL_GetError();
sHasAudioDevice = false;
} }
if (sAudioFormat.freq != sRequestedAudioFormat.freq) { if (sAudioFormat.freq != sRequestedAudioFormat.freq) {

View file

@ -33,6 +33,8 @@ public:
// Used for streaming audio from videos. // Used for streaming audio from videos.
void processStream(const void *samples, unsigned count); void processStream(const void *samples, unsigned count);
bool getHasAudioDevice() { return sHasAudioDevice; };
static SDL_AudioDeviceID sAudioDevice; static SDL_AudioDeviceID sAudioDevice;
static SDL_AudioSpec sAudioFormat; static SDL_AudioSpec sAudioFormat;
@ -44,6 +46,7 @@ private:
static SDL_AudioStream* sConversionStream; static SDL_AudioStream* sConversionStream;
static std::vector<std::shared_ptr<Sound>> sSoundVector; static std::vector<std::shared_ptr<Sound>> sSoundVector;
static std::shared_ptr<AudioManager> sInstance; static std::shared_ptr<AudioManager> sInstance;
static bool sHasAudioDevice;
}; };
#endif // ES_CORE_AUDIO_MANAGER_H #endif // ES_CORE_AUDIO_MANAGER_H

View file

@ -148,6 +148,9 @@ void Sound::play()
if (!Settings::getInstance()->getBool("NavigationSounds")) if (!Settings::getInstance()->getBool("NavigationSounds"))
return; return;
if (!AudioManager::getInstance()->getHasAudioDevice())
return;
SDL_LockAudioDevice(AudioManager::sAudioDevice); SDL_LockAudioDevice(AudioManager::sAudioDevice);
if (playing) if (playing)