Methods Summary |
---|
public void | addBuildFailedSound(java.io.File fileFail, int loopsFail, java.lang.Long durationFail)
this.fileFail = fileFail;
this.loopsFail = loopsFail;
this.durationFail = durationFail;
|
public void | addBuildSuccessfulSound(java.io.File file, int loops, java.lang.Long duration)
this.fileSuccess = file;
this.loopsSuccess = loops;
this.durationSuccess = duration;
|
public void | buildFinished(org.apache.tools.ant.BuildEvent event)Fired after the last target has finished. This event
will still be thrown if an error occurred during the build.
if (event.getException() == null && fileSuccess != null) {
// build successfull!
play(event.getProject(), fileSuccess, loopsSuccess, durationSuccess);
} else if (event.getException() != null && fileFail != null) {
play(event.getProject(), fileFail, loopsFail, durationFail);
}
|
public void | buildStarted(org.apache.tools.ant.BuildEvent event)Fired before any targets are started.
|
public void | messageLogged(org.apache.tools.ant.BuildEvent event)Fired whenever a message is logged.
|
private void | play(org.apache.tools.ant.Project project, java.io.File file, int loops, java.lang.Long duration)Plays the file for duration milliseconds or loops.
Clip audioClip = null;
AudioInputStream audioInputStream = null;
try {
audioInputStream = AudioSystem.getAudioInputStream(file);
} catch (UnsupportedAudioFileException uafe) {
project.log("Audio format is not yet supported: "
+ uafe.getMessage());
} catch (IOException ioe) {
ioe.printStackTrace();
}
if (audioInputStream != null) {
AudioFormat format = audioInputStream.getFormat();
DataLine.Info info = new DataLine.Info(Clip.class, format,
AudioSystem.NOT_SPECIFIED);
try {
audioClip = (Clip) AudioSystem.getLine(info);
audioClip.addLineListener(this);
audioClip.open(audioInputStream);
} catch (LineUnavailableException e) {
project.log("The sound device is currently unavailable");
return;
} catch (IOException e) {
e.printStackTrace();
}
if (duration != null) {
playClip(audioClip, duration.longValue());
} else {
playClip(audioClip, loops);
}
audioClip.drain();
audioClip.close();
} else {
project.log("Can't get data from file " + file.getName());
}
|
private void | playClip(javax.sound.sampled.Clip clip, int loops)
clip.loop(loops);
while (clip.isRunning()) {
// Empty block
}
|
private void | playClip(javax.sound.sampled.Clip clip, long duration)
clip.loop(Clip.LOOP_CONTINUOUSLY);
try {
Thread.sleep(duration);
} catch (InterruptedException e) {
// Ignore Exception
}
|
public void | targetFinished(org.apache.tools.ant.BuildEvent event)Fired when a target has finished. This event will
still be thrown if an error occurred during the build.
|
public void | targetStarted(org.apache.tools.ant.BuildEvent event)Fired when a target is started.
|
public void | taskFinished(org.apache.tools.ant.BuildEvent event)Fired when a task has finished. This event will still
be throw if an error occurred during the build.
|
public void | taskStarted(org.apache.tools.ant.BuildEvent event)Fired when a task is started.
|
public void | update(javax.sound.sampled.LineEvent event)This is implemented to listen for any line events and closes the
clip if required.
if (event.getType().equals(LineEvent.Type.STOP)) {
Line line = event.getLine();
line.close();
} else if (event.getType().equals(LineEvent.Type.CLOSE)) {
/*
* There is a bug in JavaSound 0.90 (jdk1.3beta).
* It prevents correct termination of the VM.
* So we have to exit ourselves.
*/
//System.exit(0);
}
|