26.07.2013 Views

Java How to Program Fourth Edition - DCC

Java How to Program Fourth Edition - DCC

Java How to Program Fourth Edition - DCC

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

1238 <strong>Java</strong> Media Framework and <strong>Java</strong> Sound (on CD) Chapter 22<br />

In addition <strong>to</strong> the sample media clips provided with this chapter’s examples on the CD,<br />

many Web sites offer an abundant supply of free-for-download audio and video clips. You<br />

can download media clips from these sites (and many others on the Internet) and use them <strong>to</strong><br />

test the examples in this chapter. We present a list of sites here <strong>to</strong> get you started. Free Audio<br />

Clips (www.freeaudioclips.com) is an excellent site for various types of audio files.<br />

The 13 Even site (www.13-even.com/media.html) provides audio and video clips in<br />

many formats for your personal use. If you are looking for MIDI audio files for use in Section<br />

22.7, check out the free MIDI clips at www.freestuffgalore.commidi.asp. Funny<br />

Video Clips (www.video-clips.co.uk) offers entertaining material. Microsoft’s<br />

downloads site (msdn.microsoft.com/downloads) contains a multimedia section<br />

providing audio clips and other media.<br />

Currently, JMF is available as an extension package separate from the <strong>Java</strong> 2 Software<br />

Development Kit. The CD that accompanies this book contains JMF 2.1.1. The most recent<br />

JMF implementation can be downloaded from the official JMF Web site:<br />

java.sun.com/products/java-media/jmf<br />

The JMF Web site provides versions of the JMF that take advantage of the performance<br />

features of the platform on which the JMF is running. For example, the JMF Windows Performance<br />

Pack provides extensive media and device support for <strong>Java</strong> programs running on<br />

Microsoft Windows platforms (Windows 95/98/NT 4.0/2000). JMF’s official Web site also<br />

provides continually updated support, information and resources for JMF programmers.<br />

Portability Tip 22.1<br />

Writing programs using JMF’s Windows Performance Pack reduces the portability of those<br />

programs <strong>to</strong> other operating systems. 22.1<br />

The rest of this chapter discusses the <strong>Java</strong> Sound API and its extensive sound-processing<br />

capabilities. Internally, the JMF uses <strong>Java</strong> Sound for its audio functions. In Sections<br />

22.5 through 22.7, we will demonstrate sampled audio playback and MIDI functionalities<br />

using <strong>Java</strong> Sound, a standard extension of the <strong>Java</strong> 2 Software Development Kit.<br />

22.2 Playing Media<br />

The JMF is commonly used <strong>to</strong> playback media clips in <strong>Java</strong> applications. Many applications<br />

such as financial managers, encyclopedias and games use multimedia <strong>to</strong> illustrate application<br />

features, present educational content and entertain users.<br />

The JMF offers several mechanisms for playing media, the simplest of which is via<br />

objects that implement interface Player. Interface Player (package javax.media)<br />

extends Controller, which is a handler for JMF-supported media.<br />

The following steps are needed <strong>to</strong> play a media clip:<br />

1. Specify the media source.<br />

2. Create a Player for the media.<br />

3. Obtain the output media and Player controls.<br />

4. Display the media and controls.<br />

Class SimplePlayer (Fig. 22.1) is a simple <strong>Java</strong> media player program that demonstrates<br />

several common features of popular media players. The SimplePlayer demo

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!