@@ -5,6 +5,7 @@ Minim minim;
55FilePlayer [] auditoryNfbFilePlayers;
66ddf.minim.ugens.Gain [] auditoryNfbGains;
77AudioOutput audioOutput;
8+ boolean audioOutputIsAvailable;
89
910// Pre-load audio files into memory in delayedSetup for best app performance and no waiting
1011void asyncLoadAudioFiles () {
@@ -16,11 +17,18 @@ void asyncLoadAudioFiles() {
1617 println (" OpenBCI_GUI: AuditoryFeedback: Loading Audio..." );
1718 for (int i = 0 ; i < _numSoundFiles; i++ ) {
1819 // Use large buffer size and cache files in memory
19- auditoryNfbFilePlayers[i] = new FilePlayer ( minim. loadFileStream(" bp" + (i+ 1 ) + " .mp3" , 2048 , true ) );
20- auditoryNfbGains[i] = new ddf.minim.ugens. Gain (- 15.0f );
21- auditoryNfbFilePlayers[i]. patch(auditoryNfbGains[i]). patch(audioOutput);
20+ try {
21+ auditoryNfbFilePlayers[i] = new FilePlayer ( minim. loadFileStream(" bp" + (i+ 1 ) + " .mp3" , 2048 , true ) );
22+ auditoryNfbGains[i] = new ddf.minim.ugens. Gain (- 15.0f );
23+ auditoryNfbFilePlayers[i]. patch(auditoryNfbGains[i]). patch(audioOutput);
24+ } catch (Exception e) {
25+ outputError(" AuditoryFeedback: Unable to load audio files. To enable this feature, please connect or turn on an audio device and restart the GUI." );
26+ audioOutputIsAvailable = false ;
27+ return ;
28+ }
2229 }
2330 println (" OpenBCI_GUI: AuditoryFeedback: Done Loading Audio!" );
31+ audioOutputIsAvailable = true ;
2432}
2533
2634class AuditoryNeurofeedback {
@@ -91,6 +99,10 @@ class AuditoryNeurofeedback {
9199 // For this button, only call the callback listener on mouse release
92100 startStopButton. onRelease(new CallbackListener () {
93101 public void controlEvent (CallbackEvent theEvent ) {
102+ if (! audioOutputIsAvailable) {
103+ outputError(" AuditoryFeedback: Unable to load audio files. To enable this feature, please connect or turn on an audio device and restart the GUI." );
104+ return ;
105+ }
94106 // If using a TopNav object, ignore interaction with widget object (ex. widgetTemplateButton)
95107 if (! topNav. configSelector. isVisible && ! topNav. layoutSelector. isVisible) {
96108 if (auditoryNfbFilePlayers[0 ]. isPlaying()) {
0 commit comments