Author: bodewig
Date: Fri Jan 29 16:25:49 2010
New Revision: 904546

URL: http://svn.apache.org/viewvc?rev=904546&view=rev
Log:
sound doesn't work on Java6.  Submitted by Ed Brannin.  PR 48637

Modified:
    ant/core/trunk/WHATSNEW
    
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/sound/AntSoundPlayer.java

Modified: ant/core/trunk/WHATSNEW
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=904546&r1=904545&r2=904546&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Fri Jan 29 16:25:49 2010
@@ -28,6 +28,9 @@
    it updated an existing property file.
    Bugzilla Report 48558.
 
+ * <sound> didn't work properly in recent Java VMs.
+   Bugzilla Report 48637.
+
 Other changes:
 --------------
 

Modified: 
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/sound/AntSoundPlayer.java
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/sound/AntSoundPlayer.java?rev=904546&r1=904545&r2=904546&view=diff
==============================================================================
--- 
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/sound/AntSoundPlayer.java
 (original)
+++ 
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/sound/AntSoundPlayer.java
 Fri Jan 29 16:25:49 2010
@@ -40,8 +40,9 @@
 /**
  * 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 @@
     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 @@
         } catch (InterruptedException e) {
             // Ignore Exception
         }
+        clip.stop();
     }
 
     /**
@@ -162,13 +177,6 @@
         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);
         }
     }
 


Reply via email to