About this tutorial
The Java Media Framework (JMF) is an exciting and versatile API that allows Java developers to process media in many different ways. This tutorial provides an overview of some of the major features of JMF, mainly through the use of working examples. Upon completion of this tutorial, you will understand the major players in the JMF architecture. You also will have worked directly with JMF, using live examples and source code that may be extended for more specific purposes.
Topics covered in this tutorial are as follows:
- Tips for downloading and installing JMF
- Major JMF classes and their uses in the JMF architecture
- Playing local media files
- Presenting a graphical user interface (GUI) for media access and manipulation
- Broadcasting media over a network
- Receiving broadcast media over a network
Almost any type of media manipulation or processing is possible through JMF. A comprehensive discussion of all the features JMF has to offer is well beyond the scope of this tutorial. Instead, we'll use three simplified media applications to learn about the framework's building blocks. In this way, the tutorial will prepare you for future study and the implementation of more specific applications.
This tutorial will walk you through the basics of working with JMF. To accomplish this, we'll create three separate working example applications. Each of these examples will build upon the previous examples, displaying different aspects of JMF's functionality.
The examples in this tutorial assume that you have used and are already familiar with the Java programming language. In addition to the core Java and JMF classes, we will be working with some of the Java AWT and Swing classes (for presenting a GUI), as well as some Java networking classes (for transmitting media over a network). Some familiarity with both the GUI and networking classes will help you more quickly understand the discussion and examples here, but are not prerequisites of this tutorial.
The example applications we'll work with are as follows:
A simple audio media player (the JMF HelloWorld application): This command-line-driven media player lets you play most audio types by simply specifying the media file name on the command line. The audio media player demo showcases mainly JMF-specific classes.
A GUI-driven media player: We'll use built-in JMF interface components to build the GUI, so little GUI programming experience will be necessary for this exercise. The media viewer demo uses some of the Java AWT and Swing classes to present GUI components to the user.
- A media broadcasting application: This application allows a local media file to be transmitted over a network. The application is flexible enough to transmit media only to a specified network node, or to broadcast it to all the nodes within a subnet. This demo uses some of the Java networking APIs to allow media transmission over a network.
As part of the third exercise, we'll modify the GUI-enabled media player to let it receive and play broadcast media.
See Resources for a listing of articles, tutorials, and other references that will help you learn more about the topics covered in this tutorial.
To run the examples in this tutorial, you need the following tools and components:
- The Java 2 platform, Standard Edition, to compile and run the demo applications
- The Java Media Framework, version 2.1.1a or above
- A properly installed and configured sound card
- One or more test machines
- The demo source files in mediaplayer.jar (see Download).
The final demo application shows how JMF can be used over a network. If necessary, the demo can be run on a single machine using the machine as both the transmitter and receiver. To see the full power of using JMF over a network, however, you will need at least two machines that are reachable on the same network.
See Resources to download the Java 2 platform, complete source files, and other tools essential for the completion of this tutorial.
The first step in installing the JMF on your machine is to download the installer through the JMF home page, which also contains links to the JMF source code and the API documentation. See Resources for a link to download JMF.
Currently, JMF has versions for Windows, Solaris, Linux, and a pure-Java version that works on any machine with a JVM. To increase performance, you should download the version that is specific to your OS. Any code that is written and compiled with an OS-specific version of JMF is portable across other OSs. For example, if you download the Solaris version of JMF and compile a number of classes, those same classes can be used on a Linux machine without any problems.
Alternatively, you may choose to download the pure-Java, or "cross-platform," version of JMF. This version doesn't employ any OS-specific libraries. The cross-platform version is a good choice if your OS doesn't have its own version of JMF installed or if you don't know what OS the target machine will be running.
After you've downloaded the JMF installer to your desktop, double-click the installer icon.
Most installers have an option to install native libraries in a system directory; for example, the Windows installer will present an option to "Move DLLs to Windows/System directory." For best results, choose this option, because it ensures the OS-specific libraries will be installed correctly.
You should also choose the option to update the system
PATH variables during
installation. If this option is turned off, remember to include the JMF jar files in the classpath when you compile or run any of the examples in this tutorial.