Skip to content

Commit 420332d

Browse files
authored
Merge pull request #1115 from OpenBCI/fix-no-audio-playback-device-error
Fix NullPointerException when no Audio Device is available from the OS
2 parents 901f73c + 63e8954 commit 420332d

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# v5.1.1
22

33
### Bug Fixes
4+
- Fix NullPointerException when no Audio Device is available from the OS (Windows and Linux) #1109 #1086
45
- Fix LSL AvgBandPower data type only one value is sent #1098
56

67
### Improvements

OpenBCI_GUI/AuditoryNeurofeedback.pde

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Minim minim;
55
FilePlayer[] auditoryNfbFilePlayers;
66
ddf.minim.ugens.Gain[] auditoryNfbGains;
77
AudioOutput audioOutput;
8+
boolean audioOutputIsAvailable;
89

910
//Pre-load audio files into memory in delayedSetup for best app performance and no waiting
1011
void 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

2634
class 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

Comments
 (0)