Browse Source

sound doesn't work on Java6. Submitted by Ed Brannin. PR 48637

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@904546 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 15 years ago
parent
commit
b30e40b92a
2 changed files with 22 additions and 11 deletions
  1. +3
    -0
      WHATSNEW
  2. +19
    -11
      src/main/org/apache/tools/ant/taskdefs/optional/sound/AntSoundPlayer.java

+ 3
- 0
WHATSNEW View File

@@ -28,6 +28,9 @@ Fixed bugs:
it updated an existing property file.
Bugzilla Report 48558.

* <sound> didn't work properly in recent Java VMs.
Bugzilla Report 48637.

Other changes:
--------------



+ 19
- 11
src/main/org/apache/tools/ant/taskdefs/optional/sound/AntSoundPlayer.java View File

@@ -40,8 +40,9 @@ import org.apache.tools.ant.Project;
/**
* This class is designed to be used by any AntTask that requires audio output.
*
* It implements the BuildListener interface to listen for BuildEvents and could
* be easily extended to provide audio output upon any specific build events occuring.
* It implements the BuildListener interface to listen for BuildEvents
* and could be easily extended to provide audio output upon any
* specific build events occurring.
*
* I have only tested this with .WAV and .AIFF sound file formats. Both seem to work fine.
*
@@ -139,8 +140,21 @@ public class AntSoundPlayer implements LineListener, BuildListener {
private void playClip(Clip clip, int loops) {

clip.loop(loops);
while (clip.isRunning()) {
// Empty block
do {
try {
long timeLeft =
(clip.getMicrosecondLength() - clip.getMicrosecondPosition())
/ 1000;
if (timeLeft > 0) {
Thread.sleep(timeLeft);
}
} catch (InterruptedException e) {
break;
}
} while (clip.isRunning());

if (clip.isRunning()) {
clip.stop();
}
}

@@ -151,6 +165,7 @@ public class AntSoundPlayer implements LineListener, BuildListener {
} catch (InterruptedException e) {
// Ignore Exception
}
clip.stop();
}

/**
@@ -162,13 +177,6 @@ public class AntSoundPlayer implements LineListener, BuildListener {
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);
}
}



Loading…
Cancel
Save