Previous | Next | Trail Map | Writing Applets | Creating an Applet User Interface


Playing Sounds

In the Java Applet package (java.applet), the Applet class and AudioClip interface provide basic support for playing sounds. Currently, the Java API supports only one sound format: 8 bit, µlaw, 8000Hz, one-channel, Sun ".au" files. You can create these on a Sun workstation using the audiotool application. You can convert files from other sound formats using an audio format conversion program.

Below are the sound-related Applet methods. The two-argument form of each method takes a base URL (generally, returned by either getDocumentBase() or getCodeBase()) and the location of the sound file relative to the base URL. You should generally use the code base for sounds that are integral to the applet. The document base is generally used for sounds specified by the applet user, such as through applet parameters.

getAudioClip(URL), getAudioClip(URL, String)(in the API reference documentation)
Return an object that implements the AudioClip interface.
play(URL), play(URL, String)(in the API reference documentation)
Play the AudioClip corresponding to the specified URL.

The AudioClip interface defines the following methods:

loop()(in the API reference documentation)
Starts playing the clip repeatedly.
play()(in the API reference documentation)
Plays the clip once.
stop()(in the API reference documentation)
[It'd be nice to have an example. Or point to one.]


Previous | Next | Trail Map | Writing Applets | Creating an Applet User Interface