JMF application-user interface components

Source: Internet
Author: User

 JMF user interface components


Play video

In the previous section, we learned how to create an application for playing audio files through the character interface. One of the most important features of JMF is that you do not need to understand the media file format to configure the media player. Everything is built in. For example, in the previous example, when MP3 format is required, we do not need to create a special player for an MP3 file.
As you will see in this section, operations on video files are equally effective. JMF provides details about all media file interfaces.
The biggest difference between processing video media and audio is that we must create a display screen that can play a video. Fortunately, JMF can process a lot of this information. As in the previous example, we will create a Player Object and use many visual components to directly create our visual media browser from the JMF object.
In this section, we will learn two examples. In this section, we & aposll walk through the second example application. Please refer to mediaplayerframe. Java in the source code distribution of the following exercises.

Examples
In this section, we will create an application that can display and run local audio and video media. As part of the exercise, we will study some gui components built into JMF. Familiarity with AWT and swing will help you understand this example, but this is not necessary. Unless you need to directly involve the jmf gui components, or we will not detail the source code. You can find detailed descriptions not involved here in the source code annotations.
Many concepts, classes, and methods used in this example are similar to those in the first example. The basic operations for creating a player are mostly the same. The biggest difference is that we need to study the Player Object more deeply, especially when we need to obtain media information from the player.

How to start
The Video Player example is designed to run through the command line like the audio playback example, but this example needs to be built on the GUI. As in the previous section, we first call the application through the media file name. The application then displays a form with operable media components.
In the row starting with mediaplayerframe, we defined the class and extended the class javax. Swing. jframe class. This is how to make a media player look like a separate form on the desktop. After any client program creates a playback object, it can be displayed by calling the show () method defined in the jframe class.
Below is a screen where mediaplayerframe is playing an MPEG movie:

Obtain GUI Components
The player interface has some methods to obtain the involved items of the selected visual components. In mediaplayerframe, we use the following components:
· Player. getvisualcomponent () is a visual component used to play all the video media.
· Player. getcontrolpanelcomponent () is a visual component (including start, stop, and playback) that operates the timeline. It also contains useful information about media streams.
· Player. getgaincontrol (). getcontrolcomponent () is a visual component for operating Volume (increase. The getgaincontrol () method returns a gaincontrol instance that can be used to change the increase level of a program.

Use visualization Components
The preceding interface methods return an instance of the Java. AWT. component class. No instances are visible components that can be loaded to our forms. These components are directly related to the player, so the processing of all the visual elements on these components will change accordingly after the player plays the media.
Before adding these components to our form, make sure they are not empty. Because not all media players include every visual component, we only need to add relevant player components. For example, an audio player has no visual components, so getvisualcomponent () returns NULL. You do not want to add visual components to the audio player form.

Obtain special media control
A Player instance can also expose its control through the getControl () and getControls () methods. getControls () returns a control object set, while getControl () returns a control object set. Different player types can be used as special operations to expose the specified media type from the control set, or to obtain the transmission mechanism of the media. If you are writing a Player that only supports certain media types, you need to rely on some Control objects available in the Player instance.
Since our player is very abstract and designed to play a variety of different media types, we simply expose all the Control objects for users. If you find any extended control set, you can use the getControlComponent () method to add the corresponding visible control to the tag panel. In this way, you can observe all the components on the player. The following code snippet exposes all the control objects to users:

Control[] controls = player.getControls();
for (int i = 0; i< controls.length; i++) {
if (controls[i].getControlComponent() != null) {
tabPane.add(controls[i].getControlComponent());
}
}

To enable a real application to do something useful with the Control instance (except for displaying visual components), the application needs to know the special type of the Control and allocate it. Then, applications can use these controls to control media programs. For example, if you know that the media you often use exposes javax. media. control. you can use the QualityControl interface to change the attribute settings on the QualityControl interface.

Use a medialocator
The biggest difference between our New GUI-based Media Player and our first simple Player is that we use a MediaLocator object instead of a URL to create a Player instance, as shown below:

public void setMediaLocator(MediaLocator locator) throws IOException,
NoPlayerException, CannotRealizeException {
setPlayer(Manager.createRealizedPlayer(locator));
}

We will discuss the cause of this change in a later chapter. Currently, the MediaLocator object and URL descriptions on the resource site on the network are considered very similar. In fact, you can create a MediaLocator from a URL or get a URL from MediaLocator. Create a MediaLocator in a URL of our new Media Player and use this MediaLocator to create a Player through the file.

Compile and run mediaplayerframe
Compile the sample program by entering javac mediaplayerframe. Java in the command prompt line. A file named mediaplayerframe. class will be created in the working directory.
In the command prompt line, type the following line program:

java MediaPlayerFrame mediaFile

You need to replace mediafile with a media file on your local machine (either audio or video files are acceptable ). All relative file names are relative to the current working directory. You will see a window showing the GUI control set for controlling media files. For more information about the list of audio and video files supported by JMF, see resources on 23 pages.
If the initial compilation fails, make sure that the jmf jar file is included in the current classpath environment variable.

Mediaplayerframe in action
A video player that you saw before this section is playing the screen of the MPEG video file. The following screen shows an audio player playing an MP3 file:
To learn more examples in this exercise, view the complete mediaplayerframe source code.

 

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.