The Java Media Framework (JMF) is an exciting and versatile API that the Java 2 platform, complete source files, and other tools essential for. Java Media Framework API (JMF). 19 January One of JMF’s important design considerations is to support standard protocols. JMF provides. Essential Jmf – Java Media Framework has 2 ratings and 0 reviews. Essential JMF: Java Media Framework helps you master the key elements of JMF developm.

Author: JoJolkis Kagazahn
Country: Guinea-Bissau
Language: English (Spanish)
Genre: Technology
Published (Last): 8 March 2017
Pages: 295
PDF File Size: 20.98 Mb
ePub File Size: 19.75 Mb
ISBN: 243-4-89885-284-5
Downloads: 76242
Price: Free* [*Free Regsitration Required]
Uploader: Kajinris

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 mesia examples and source code that may be extended for more specific purposes. 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.

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. As part of the third exercise, we’ll modify the GUI-enabled media player to let it receive and play broadcast media. See Related topics for a listing of articles, tutorials, and other references that will help you learn more about the topics covered in this tutorial. The final demo application shows how JMF can be used over a network.

Java Media Framework API (JMF) | Open Textbooks for Hong Kong

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 Related topics to download the Java 2 platform, complete source files, and other tools essential for the completion of this tutorial. See Related topics for a link to download JMF. To increase performance, you should download the version that is specific to your OS.

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.

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. In this section, we’ll walk through the first exercise of creating a simple audio player. This example introduces you to the Manager class and the Player interface, which are two of the major pieces in building most any JMF-based application.

The functional goal of this example is to play a local audio file famework a mediq interface. We’ll walk through the source code and review what is happening in each line. Refer to the SimpleAudioPlayer. The first few lines of the SimpleAudioPlayer class include the following calls, which import all necessary classes:.


We’ll focus on the Manager class and the Player interface in this section, and deal with some of the other javax. In addition to the import javax. In the next code fragment, the public class SimpleAudioPlayer and the Player instance variable are defined:. The term Player may sound quite familiar, because it is based on our common use of audio- and video-based media players. In fact, instances of this eessential act much like their real-life counterparts. Player s expose methods jmmf relate to the functions of a physical media player such as a stereo system or VCR.

For example, a JMF media Player has the ability to start and stop a stream of media.

We will use the start and stop functionality of the Player medis this section. JMF makes it quite simple to obtain a Player instance for a given media file. The Manager class acts as a factory for creating many of the specific interface types exposed in JMF, including the Player interface.

Therefore, the Manager class is responsible for creating our Player instance, as shown below:. If you’re following along with the source for this section, you may have noticed that the Framewirk class contains other methods for creating Player instances. Essentiap explore some of these methods — such as passing in instances of a DataSource or MediaLocator — in a later section. JMF defines a number of different states that a Player instance may be in.

Essential Jmf – Java Media Framework

These states are as follows:. Because working with media is often quite resource intensive, many of the methods exposed by JMF objects are framewor, and allow for asynchronous notification of state changes mefia a series of event listeners. For example, a Player must go through both the Prefetched and Realized states before it may be started.

Because these state changes can take some time to complete, a JMF media application can assign one thread to the initial creation of a Player instance, then move on to other operations. When the Player is ready, it will notify the application of its state changes. In a simple application such as ours, this type of versatility is not so important. For this reason, the Manager class also exposes utility methods for creating Realized players.

Calling a createRealizedPlayer method causes the calling mava to block until the player reaches the Realized state. To call a non-blocking player-creation method, we use one of the createPlayer methods on the Manager class.

The following line of code creates a Realized player, which we need in our example application:. Setting up a Player instance to be started or stopped is as simple as calling the easily recognized methods on the Playeras shown here:. Calling the play method on the Framewrk class simply delegates the call to the start method on the Player instance. After calling this method, you should hear the audio file framewofk through the local speakers. Likewise, the stop method delegates to the player to both stop and close the Player instance.

Closing the Player instance frees any jaba that were used for reading or playing jjf media file. Because this is a simple example, closing the Player is an acceptable way of ending a session. In a real application, however, you should carefully consider whether you want to get rid of the Player before you close it. Once you’ve closed the player, you will have to create a new Player instance and wait for it to go frammework all of its state changes before you can play your media again.

Finally, meeia media player application contains a main method, which lets it be invoked from the command line by passing in the file name. In the main method, we make the following call, which creates the SimpleAudioPlayer:. The only other thing we have to do before we can play our audio file is to call the play method on the created audio player, as shown here:.


To stop and clean up the audio player, we make the following call, also found in the main method:. Compile the example application by typing javac SimpleAudioPlayer. This creates the SimpleAudioPlayer.

Java Media Framework basics

Replace audioFile with the file name of an audio file on your local system. Any relative file names will be resolved relative to the current working directory. You should see some messages indicating the file that is being played.

To stop playing, press the Enter key. In the previous section, we walked through the steps of setting up an application that lets you play audio files through a command-line interface.

One of the great features of JMF is that you don’t need to know anything about the media file types in order to configure a media player; everything is handled internally. For instance, in our previous example, we did not need to tell the application to create a Player specifically for an MP3 file, since the MP3 setup was handled for us.

As you will see in this section, the same holds true for handling video files. JMF handles all of the details of interfacing with the media file types. The main difference in dealing with video media rather than audio is that we must create a visual representation of a screen to be able to display the video. Luckily, JMF handles many of these details for us.

We will create a Player instance much like we did in the previous example, and obtain many of the visual components to create our visual media viewer directly from JMF objects. In this section, we’ll walk through the second example application. Refer to the MediaPlayerFrame. In this section we’ll create an application that can display and run both audio and video media from your local machine.

Familiarity with AWT and Swing will help you follow the examples, but is not required. You will find that many details that are not covered here are explained in the source code comments. Most of the concepts, classes, and methods we’ll use in this example will be familiar from the first example. The basics of setting up the Player are almost identical. The biggest difference is that we’re going to dig a little deeper into the Player instance, particularly when it comes to getting information about the media from the Player.

The video player example is designed to run from the command line, much like the audio player example did, but this example is GUI based.

We start by invoking the application and passing in the file name of the media, just as we did in the previous section. Frameworm, the application displays a window with components that let us manipulate the media. In the opening lines of the MediaPlayerFrame we define the class and extend the javax. This is how we define our media player as a separate window on the desktop.

Any client that creates an instance of our media player class may then display it by meia the show method defined on the JFrame class. View image at full size.

Java Media Framework basics

The Player interface exposes methods to obtain references to selected visual components. In the MediaPlayerFrame we use the following components:. Frameworl of the above interface methods return an instance of the java.