From b30e40b92a0f65dccc98417385209cf0350b3fb5 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Fri, 29 Jan 2010 16:25:49 +0000 Subject: [PATCH] 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 --- WHATSNEW | 3 ++ .../optional/sound/AntSoundPlayer.java | 30 ++++++++++++------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index 5b02e58d5..74f91305d 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -28,6 +28,9 @@ Fixed bugs: it updated an existing property file. Bugzilla Report 48558. + * didn't work properly in recent Java VMs. + Bugzilla Report 48637. + Other changes: -------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/sound/AntSoundPlayer.java b/src/main/org/apache/tools/ant/taskdefs/optional/sound/AntSoundPlayer.java index 6d1966c89..399e71754 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/sound/AntSoundPlayer.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/sound/AntSoundPlayer.java @@ -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); } }