If you know Java, multimedia programming is a piece of cake. Last month, in Part 1, you saw how many parts of the Java Media Framework (JMF) classes and interfaces can integrate together. In this article, you'll see working JMF code performing multimedia functions.
Read the whole "Program Multimedia with JMF" series:
However, before you start coding with JMF, you must install the reference implementation and the supporting applications as discussed below. You should also be aware of the hardware and software requirements. Examples in this article were tested using a Pentium III 800-MHz PC on Windows 2000 with a Logitech USB camera and a built-in microphone. Therefore, the solution presented here could be Windows-specific. Even though the code should not change when deployed to other platforms, the JMF reference implementation is not available for all Java platforms. The reference implementation is not currently available for Linux users, for instance.
To use JMF, you won't find it difficult to meet the hardware and software requirements. Your old 166-MHz Pentium proves sufficient as long as it has at least 32 MB of RAM. JMF can also run on 166-MHz or greater Power PC or UltraSparc systems. You need a SoundBlaster-compatible card for audio playback if you want sound. If you happen to use an AIX machine, you can use an Ultimedia-compatible sound card.
On Windows, the software requirements comprise:
Yes, you definitely need to download the Java Media Framework 2.1 reference implementation. Once at the download page, you can choose from the following:
As a Java developer, you may be tempted to download the "Cross-platform Java" version. However, select the "Windows Performance Pack" if you are working with Windows. The all-Java version isn't ideal, as it doesn't support audio and video capture. (Also, you may wish to check out the list of known platform-specific issues.)
In contrast to the all-Java version, JMF's Windows version supports all video capture devices that employ the VFW (Video for Windows) interface. Moreover, with this version, some cameras have been tested by Sun engineers. These include:
In fact, JMF's Windows version supports almost any capture device. For the list of supported capture devices, go to: http://java.sun.com/products/java-media/jmf/2.1/formats.html#Capturers.
After you download the JMF 2.1 into a directory, double-click the jmf-2_1-win.exefile to install the reference implementation with its classfiles and native libraries for running JMF players. Afterward,
you need to make sure that InstallShield properly configured your CLASSPATH and PATH during installation. If not, you can
do it manually with the following command:
set CLASSPATH=%WINDIR%\java\classes\jmf.jar;%WINDIR%\java\classes\sound.jar;.;%CLASSPATH%
Your PATH should be set to include the JMF library files:
set PATH=%WINDIR%\System32;%PATH% (on Windows NT) set PATH=%WINDIR%\System;%PATH% (on Windows 95/98)
If you later have a problem with the installation, Sun provides the JMF Diagnostics applet to verify that JMF is set up properly on your system.
If you plan to use a capture device such as a camera, you must make sure you have installed the correct device driver for
that capture device. In addition, you need the JMFRegistryapplication.
The JMFRegistry, a standalone Java application, registers new DataSources, MediaHandlers, PlugIns, and capture devices with JMF so that you can use them with your JMF 2.1 installation. You need to run JMFRegistryonly once to register all capture devices available on the system.
After you run JMFRegistryfrom the command line or inside your Java tool, you should see a window similar to Figure 1.
Figure 1. Register your capture
device with JMFRegistry
Click on thumbnailto view
full-size image. (71 KB)
Click the "Capture Devices" tab, and then click the "Detect Capture Devices" button. A list should display all the audio and
video capture devices on the system. As seen in Figure 1, JMFRegistryfound JavaSound audio capture, a Logitech USB Video Camera, and Microsoft WDM Image Capture. Clicking a list item will display
all formats that can be used for that capture device. For example, the Logitech USB camera in Figure 1 supports RGB color
with a resolution of 352x288, 160x120, and so on.
If JMFRegistryfails to detect your capture device, it means there is something wrong with the device driver, installation process, or both.
JMFRegistryalso enables you to rearrange the search order and remove registered extensions.
When programming with JMF, it's helpful to have the JMF API specification. Note that JMF 2.1 is an implementation update, which means the implementation features new updates and fixes, but uses the same API as defined in JMF 2.0.
Also helpful are the sample JMF applications. These applications, especially JMStudio, contain the source code that you can consult when you want to learn more or when you have a problem with your code.
Due to space limitations, it's impossible to implement all of JMF 2.1's features in our JMF project. I therefore chose three basic functions that you will always need with JMF:
The capture devices function must be run prior to capturing any audio and video data, but it's not needed to play multimedia files.
ThanksBy Anonymous on October 10, 2009, 1:29 amI'm new with JMF. Thanks for this helpful.
Reply | Read entire comment
thanks for the tutorialBy Anonymous on September 7, 2009, 6:45 amthanks for the tutorial
Reply | Read entire comment
View all comments