Name

sound

Synopsis

Plays a sound file at the end of the build process. The <sound> element must appear in one of the Ant targets that is executed during the build, but the sound is not played until the build is complete. This task relies on Sun’s Java Media Framework (JMF), which is included in JDK 1.3 and later. For earlier versions of Java, JMF is available for download at http://java.sun.com/products/java-media/sound/.

Attributes

None.

Content

0,1 nested <fail> elements (1.3, 1.4)

Defines the sound to play when the build fails.

0,1 nested <success> elements (1.3, 1.4)

Defines the sound to play when the build succeeds.

Both nested elements are implemented by the same class, supporting the following attributes:

source (1.3, 1.4, File, Y)

The name of a sound file to play. If this is a directory, one file is picked at random. For this reason, all files in the directory must be sound files. The task is tested with WAV and AIFF files.

duration (1.3, 1.4, long, N)

The maximum number of milliseconds to play the sound.

loops (1.3, 1.4, int, N)

The number of times to repeat the sound. Defaults to 0. If 1, the sound repeats once and therefore plays twice. Even if several iterations are requested, the total time spent by this task does not exceed the value specified by duration.

Example Usage

Plays applause at the end of the build, or plays a bomb exploding if an error occurs:

<target name="compile" depends="prepare"> <sound> <!-- limit the applause to 2 seconds --> <success duration="2000" source="APPLAUSE.WAV"/> ...

Get Ant: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.