Retrieving and Using Sounds

Java supports the playback of sound files through the Applet class, and you can play a sound one time only or as a repeating sound loop.

Prior to Java 2, the language could handle only one audio format: 8KHz mono AU with mu-law encoding (named for the Greek letter "μ", or mu). If you wanted to use something that was in a format such as WAV, you had to translate it to mu-law AU, often at a loss of quality.

Java 2 adds much fuller support for audio. You can load and play digitized sound files in the following formats: AIFF, AU, and WAV. Three MIDI-based song file formats also are supported: Type 0 MIDI, Type 1 MIDI, and RMF. The greatly improved sound support can handle 8- or 16-bit audio data in mono or stereo, ...

Get Sams Teach Yourself Java 2 in 21 Days, Second Edition 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.