Skip to content

Commit

Permalink
debugging audio playback
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre Lison committed Apr 25, 2015
1 parent d2fae08 commit fa50dfd
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/opendial/datastructs/SpeechOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void play(Mixer.Info outputMixer) {
*/
public void waitUntilPlayed() {
try {
if (player != null) {
if (player != null && player.isActive()) {
synchronized (player) {
player.wait();
}
Expand Down Expand Up @@ -163,12 +163,15 @@ final class StreamPlayer implements Runnable {
* @throws LineUnavailableException if the audio line is unavailable
*/
public StreamPlayer(Mixer.Info outputMixer) throws LineUnavailableException {
synchronized (this) {
if (outputMixer != null) {
line = AudioSystem.getSourceDataLine(stream.getFormat(), outputMixer);
}
else {
line = AudioSystem.getSourceDataLine(stream.getFormat());
}
line.open(stream.getFormat());
}
}

/**
Expand All @@ -186,14 +189,18 @@ public synchronized void close() {
log.warning("unable to close output, aborting. Error: " + e.toString());
}
}


public synchronized boolean isActive() {
return line.isOpen();
}

/**
* Plays the audio.
*/
@Override
public void run() {
try {
line.open(stream.getFormat());
line.start();
int nBytesRead = 0;
byte[] abData = new byte[1024 * 16];
Expand Down

0 comments on commit fa50dfd

Please sign in to comment.