Chapter 22 Java Media Framework and Java Sound (Fedora web server)
Friday, August 31st, 2007Chapter 22 Java Media Framework and Java Sound (on CD) 1249 Performance Tip 22.1 Starting the Player takes less time if the Player has already prefetched the media before invoking start. When the media clip ends, the Player generates a ControllerEvent of type EndOfMediaEvent. Most media players rewind the media clip after reaching the end so users can see or hear it again from the beginning. Method endOfMedia (lines 249 253) handles the EndOfMediaEventand resets the media clip to its beginning position by invoking Player method setMediaTime with a new Time (package javax.media) of 0 (line 251). Method setMediaTime sets the position of the media to a specific time location in the media, and is useful for jumping to a different part of the media. Line 252 invokes Player method stop, which ends media processing and places the Player in state Stopped. Invoking method start on a Stopped Player that has not been closed resumes media playback. Often, it is desirable to configure the media before presentation. In the next section, we discuss interface Processor, which has more configuration capabilities than interface Player. Processors enable a program to format media and to save it to a file. 22.3 Formatting and Saving Captured Media The Java Media Framework supports playing and saving media from capture devices such as microphones and video cameras. This type of media is known as captured media. Capture devices convert analog media into digitized media. For example, a program that captures an analog voice from a microphone attached to computer can create a digitized file from a that recording. The JMF can access video capture devices that use Video for Windows drivers. Also, JMF supports audio capture devices that use the Windows Direct Sound Interface or the Java Sound Interface. The Video for Windows driver provides interfaces that enable Windows applications to access and process media from video devices. Similarly, Direct Sound and Java Sound are interfaces that enable applications to access sound devices such as hardware sound cards. The Solaris Performance Pack provides support for Java Sound and Sun Video capture devices on the Solaris platform. For a complete list of devices supported by JMF, visit JMF s official Web site. The SimplePlayer application presented in Fig. 22.1 allowed users to play media from a capture device. A locator string specifies the location of a capture device that the SimplePlayer demo accesses. For example, to test the SimplePlayer s capturing capabilities, plug a microphone into a sound card s microphone input jack. Typing the locator string javasound:// in the Open Location input dialog specifies that media should be input from the Java Sound-enabled capture device. The locator string initializes the Media- Locator that the Player needs for the audio material captured from the microphone. Although SimplePlayer provides access to capture devices, it does not format the media or save captured data. Figure 22.2 presents a program that accomplishes these two new tasks. Class CapturePlayerprovides more control over media properties via class DataSource (package javax.media.protocol). Class DataSource provides the connection to the media source, then abstracts that connection to allow users to manipulate it. This program uses a DataSource to format the input and output media. The DataSourcepasses the formatted output media to a Controller, which will format it
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.