Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Implemented error handling for audio device initialization

If there was a problem initializing the AudioDeviceManager, we show an
AlertWindow with Retry/Quit options.  Unfortunately, this doesn't fix the bug I
was initially trying to fix, because sometimes initialize() returns OK while
setting the AudioDeviceManager to null.
  • Loading branch information...
commit f92cfd1eeb2597dd0fd219d46730c215054f6252 1 parent 3c4d1c6
@akmokhtari authored
Showing with 28 additions and 8 deletions.
  1. +28 −8 Source/Audio/AudioComponent.cpp
View
36 Source/Audio/AudioComponent.cpp
@@ -27,14 +27,34 @@
AudioComponent::AudioComponent() : isPlaying(false)
{
-
- deviceManager.initialise(0, // numInputChannelsNeeded
- 2, // numOutputChannelsNeeded
- 0, // *savedState (XmlElement)
- true, // selectDefaultDeviceOnFailure
- String::empty, // preferred device
- 0); // preferred device setup options
-
+ // if this is nonempty, we got an error
+ String error = deviceManager.initialise(0, // numInputChannelsNeeded
+ 2, // numOutputChannelsNeeded
+ 0, // *savedState (XmlElement)
+ true, // selectDefaultDeviceOnFailure
+ String::empty, // preferred device
+ 0); // preferred device setup options
+ if (error != String::empty)
+ {
+ String titleMessage = String("Audio Device Initialization Error");
+ String contentMessage = String("There was a problem grabbing the audio device:\n" + error);
+ // this uses a bool since there's only two options
+ // also, omitting parameters works fine, even though the docs don't show defaults
+ bool retryButtonClicked = AlertWindow::showOkCancelBox(AlertWindow::WarningIcon,
+ titleMessage,
+ contentMessage,
+ String("Retry"),
+ String("Quit"));
+
+ if (retryButtonClicked)
+ {
+ error = deviceManager.initialise(0, 2, 0, true, String::empty, 0);
+ } else { // quit button clicked
+ JUCEApplication::quit();
+ }
+ }
+
+
AudioIODevice* aIOd = deviceManager.getCurrentAudioDevice();
std::cout << "Got audio device." << std::endl;
Please sign in to comment.
Something went wrong with that request. Please try again.