Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Error handling for when an audio device isn't found

Sometimes initialize() returns no error string, but will not find an audio
device, leaving aIOd == null.  This checks for that, and aborts the app with an
informational dialog window if so.
  • Loading branch information...
commit 0f0bedd44b1c3c750805ccca1aab8cf386d232bb 1 parent f92cfd1
@akmokhtari akmokhtari authored
Showing with 31 additions and 18 deletions.
  1. +31 −18 Source/Audio/AudioComponent.cpp
View
49 Source/Audio/AudioComponent.cpp
@@ -36,30 +36,43 @@ AudioComponent::AudioComponent() : isPlaying(false)
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();
- }
+ String titleMessage = String("Audio device initialization error");
+ String contentMessage = String("There was a problem initializing the audio device:\n" + error);
+ // this uses a bool since there are only two options
+ // also, omitting parameters works fine, even though the docs don't show defaults
+ bool retryButtonClicked = AlertWindow::showOkCancelBox(AlertWindow::QuestionIcon,
+ titleMessage,
+ contentMessage,
+ String("Retry"),
+ String("Quit"));
+
+ if (retryButtonClicked)
+ {
+ // as above
+ error = deviceManager.initialise(0, 2, 0, true, String::empty, 0);
+ } else { // quit button clicked
+ JUCEApplication::quit();
+ }
}
AudioIODevice* aIOd = deviceManager.getCurrentAudioDevice();
+ // the error string doesn't tell you if there's no audio device found...
+ if (aIOd == 0)
+ {
+ String titleMessage = String("No audio device found");
+ String contentMessage = String("Couldn't find an audio device. ") +
+ String("Perhaps some other program has control of the default one.");
+ AlertWindow::showMessageBox(AlertWindow::InfoIcon,
+ titleMessage,
+ contentMessage);
+ JUCEApplication::quit();
+ }
+
+
std::cout << "Got audio device." << std::endl;
- String devType = deviceManager.getCurrentAudioDeviceType();
String devName = aIOd->getName();
std::cout << std::endl << "Audio device name: " << devName << std::endl;
@@ -76,7 +89,7 @@ AudioComponent::AudioComponent() : isPlaying(false)
String msg = deviceManager.setAudioDeviceSetup(setup, false);
- devType = deviceManager.getCurrentAudioDeviceType();
+ String devType = deviceManager.getCurrentAudioDeviceType();
std::cout << "Audio device type: " << devType << std::endl;
float sr = setup.sampleRate;
Please sign in to comment.
Something went wrong with that request. Please try again.