JMF of java media framework

Source: Internet
Author: User
Tags prefetch

If you want to use swing in Java to play music and videos, including recording and video capturing, you need to use the java media framework JMF.

The java media framework (JMF) enables you to write powerful multimedia programs without worrying about the complex implementation details at the underlying layer. JMF APIs are relatively simple to use, but can meet the needs of almost all multimedia programming. In this article, I will introduce you how to write multimedia programs with very little code.

Java Multimedia Framework (JMF) contains many APIs for processing multimedia. It is a very complex system. It may take weeks to fully understand the system. However, this article will mainly introduce several core interfaces and classes of JMF, then, a simple example is provided to show you how to program using this interface.

The latest version of JMF is 2.1. Sun introduces multimedia processing capabilities to Java. The following is an overview of features supported by JMF:

● Various media files, such as Au, Avi, Midi, MPEG, QuickTime, and WAV, can be played in Java applets and applications.

● You can play media streams downloaded from the Internet.

● Audio and video can be captured and saved as multimedia files using microphones and cameras.

● Process multimedia files and convert the file format.

● Upload audio and video data streams to the Internet.

● Broadcast audio and video data on the Internet.


JMF Structure

In order to better describe the JMF structure, let's make a simple analogy with stereo sound. When you play a CD record on a CD server, the CD record provides a music signal to the system. The data is recorded in the recording studio using the mic wind and other similar devices. The CD player transmits the music signal to the Speaker of the system. In this example, the microphone is an audio capturing device. The CD is a data source, and the speaker is an output device.

The structure of JMF is very similar to that of the stereo sound system. In the subsequent articles, you will encounter the following terms:

● Data Source)

● Capturing device (capture device, including video and audio capturing devices)

● Player)

● Processor)

● Data Format)

● Manager)

Let's take a look at what these terms mean.

1. Data Source

Just like saving a song in a CD, the data source contains a media data stream. In JMF, The datasource object is a data source, which can be a multimedia file or a data stream downloaded from the Internet. Once you have determined the position and type of the datasource object, the object contains the multimedia location information and software information that can play the multimedia. After a datasource object is created, it can be sent to the player object. The Player Object does not need to care about how multimedia in the datasource is obtained and what format is used.

In some cases, you need to combine multiple data sources into one data source. For example, when you make a video, you need to combine the audio data source and video data source. JMF supports data source merging, which will be mentioned in the following example.

2. Intercept Devices

A device is a hardware device that can intercept audio or video data, such as a microphone or camera. The captured data can be sent to the Player Object for processing.

3. Player

In JMF, the corresponding player interface is player. The player object uses the audio/video data stream as the input, and then outputs the data stream to the speaker or screen, just as the CD player reads the songs in the CD record and sends the signal to the speaker. The player object has multiple States. JMF defines the six states of JMF. Under normal circumstances, the player object must go through each State before playing multimedia. The following describes the statuses.

● Unrealized: in this state, the player object has been instantiated but does not know any information about the multimedia to be played.

● Realizing: When the realize () method is called, The State of the Player Object changes from unrealized to realizing. In this state, the player object is determining the resources it needs to occupy.

● Realized: in this state, the player object has determined the resources it needs and the type of multimedia to be played.

● Prefetching: When the prefectch () method is called, The State of the Player Object changes from realized to prefetching. In this status, the player object is preparing for playing multimedia, including loading multimedia data and obtaining exclusive resources. This process is called prefetch ).

● Prefetched: When the Player Object completes the prefetch operation, it reaches this state.

● Started: After the start () method is called, The Player Object enters this state and plays multimedia.

4. Processor

Processor is a player. In jmf api, the processor interface inherits the player interface. In addition to all functions supported by the player object, the processor object can also control the processing of the input multimedia data stream and output data to other player objects or processor objects through the data source.

In addition to the six States mentioned in the player, the processor object also contains two new states, which are after the unrealized state but before the realizing state.

● Processing ing: After the configure () method is called, the processor object enters this state. In this status, the processor object connects to the data source and obtains the format of the input data.

● Configured: After the data source is connected and the information in the input data format is obtained, the processor object is in the CONFIGURED state.

5. Data Format

The format object stores multimedia format information. The object itself does not record information about multimedia encoding, But it stores the encoding name. The format subclass includes the audioformat and videoformat classes. viedeofomat has six subclasses: h261format, h263format, indexedcolorformat, formatted format, rgbformat, and yuvformat.

6. Manager

JMF provides the following four types of managers:

● MANAGER: the manager is equivalent to an interface between two classes. For example, if you want to play a datasource object, you can use the manager object to create a player object to play it. You can use the manager object to create player, processor, datasource, and datasink objects.

● Packagemanager: This Manager stores the JMF class registration information.

● Capturedevicemanager: The manager saves the registration information of the intercepted device.

● Pluginmanager: This Manager stores the registration information of the JMF plug-in.


Create a Player Object

In JMF programming, the most common task is to create a player object. You can create a Player Object using the createplayer () method of the manager class. The manager object uses a multimedia URL or medialocator object to create a player object. After obtaining a player object, you can call the getvisualcomponent () method to obtain the image component of the Player Object (visual component, which can play multimedia images on the image component ). Add the image parts to the application or applet interface. The Player Object also contains a control panel,
You can control the playing, stopping, and pausing of a media set.

Many methods in the player class are called only when the Player Object is in the realized state. To ensure that the player object has reached this state, you need to use the createrealizeplayer () method of manager to obtain the Player Object. However, for the START () method, you can call the Player Object before it reaches the prefetched state. It can automatically convert the player state to the started state.


Intercept Multimedia Data

The interception of multimedia data is another very important function in JMF programs. You can take the following steps to intercept data:

● Query capturedeviecemanager to obtain the desired screenshot device.

● Obtain the capturedeviceinfo object corresponding to the device.

● Obtain the medialocator object from the capturedeviecinfo object and use it to create a datasource object.

● Use the datasource object to create a player object or processor object.

● Call the START () method to start intercepting multimedia data.

You can use the capturedevicemanager object to obtain available video and audio capturing devices in the system. Call Getdevicelist () to obtain the device list. Each device corresponds to a captruedeviceinfo object. You can also call the getdevice () method of the capturedeviecemanager object to obtain a specific capturedeviceinfo object. Before using a device to intercept multimedia data, you also need to obtain the medialocator object corresponding to the device from the capturedeviceinfo object. Then you can directly use medialocator to construct the player.
Or processor instance, you can also use medialocator to construct a datasource object, and then send the datasource object to the player or processor object. Finally, the START () method is called to intercept multimedia data.


Install jmf2.1 in Windows

Before using JMF for programming, you need to install JMF. There are also some requirements on hardware. Because the code in this article is written and tested in Windows 2000, the software required for the operating system mentioned in this article is related to Windows. Although Java is cross-platform, JMF is an exception-not all platforms implement JMF.

Hardware and software requirements

In terms of hardware, you need a sound card compatible with soundblaster. It is best to use a chip above Pentium III. It is recommended that the memory size be no less than 64 MB. You also need to install the following software:

● Win7, Windows NT 4.0, windows or Windows XP.

● JDK 1.1.6 or later Windows versions.

● JMF class and dynamic library

Install jmf2.1 in Windows

Run jmf-2_1_1b-windows-i586.exe after jmf2.1is downloaded. This program will install jmf2.1 to the directory you specified. After the installation is successful, check that the installation program correctly sets the classpath and PATH environment variables. The classpath must contain JMF. jar and sound. Jar. The path must contain the JMF dynamic library.


Jmfregistry

If you want to use a video or audio capture device, you need to confirm that the driver of these devices is installed. In addition, you also need to run the jmfregistry application. Jmfregistry can register new data sources, media processors, INS, video and audio capturing devices with JMF before you can use them in your program. You only need to run jmfregistry once to register all the video and audio capturing devices in the system.

After you run jmfregistry, the window shown in Figure 1 is displayed:



Figure 1 register a video and audio capturing device through jmfregistry (Video not installed)

Select the "Capture Devices" tab and press the "detect Capture Devices" button. The program will automatically detect the video and audio capturing devices in the system. The names of all detected devices are listed in the class Table box on the left. In Figure 1, we can see that jmfregsitery has discovered mongoound audio capture, VFW: Logitech USB video camera: 0, and VFW: Microsoft WDM image capture (win32): 1. Click a device to view the supported video or audio formats. If jmfregistry cannot detect the device, it may be that the driver of the device is not properly installed.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.