Loading
View RSS Feed

Raks' Blog

How To Implement User Interface For Media Components Using JMF API?

Rate this Entry
The JMF API provides user interface components for the media components. These user interface components are used to build a GUI that controls the working of the media components.

Obtaining Visual Components
The Player interface declares the getVisualComponent method to obtain user interface components for the media component that it represents. This method returns a Component object that displays the corresponding media. This Component object is added to the display frame built to display the media.
Code for obtaining Visual Components for a Player Instance are as follows:-
Code:
public void getVisualComponent(URL url)
{
	Panel components;
	Component visualComponent;
	Label status;

	try
	{
	/* create a new Player instance using the URL specified in the argument */
	Player player = Manager.createPlayer(url);
	/* create a new Panel to hold the visual components */
	components = new Panel(new BorderLayout());

	/* get the visual component associated with the Player instance */
	visualComponent = player.getVisualComponent();

	/* check if the visual component was obtained successfully */
	if ( visualComponent != null )
	components.add (visualComponent, BorderLayout.CENTER);
	else
	{
		status = new Label("No visual component available");
		components.add(status,BorderLayout.CENTER);
	}
	}
	catch(Exception e)
	{
		System.out.println(e);
	}
}

Obtaining Control Components
The Player interface provides the getControlComponent and getControls methods to obtain control components for the media components. These control components returned by the getControlComponent or getControls methods control the working of the media components.

The getControlComponent method returns a Component object that controls the playback of the media. This object provides controls to start, stop, and rewind the media. It also provides information about the media being played.

The getControls method returns an array of Control objects associated with the Player instance. When the getControls method is invoked on these Control objects, it returns a Control object that is specific to the media type represented by the Player instance. To obtain the control component for this Control object, you use the getControlComponent method of the Control class.

If no control component is available for a Control object, the getControlComponent method returns null. The control components returned by the getControlComponent method can be added to the user interface.

Code for Obtaining Control Components for a Player Instance are as follows:-
Code:
public void getControlComponent(URL url)
{
Player player;
Component controlComponent;
JTabbedPane jtp;
Label status;
	try
	{
		/* create a new Player instance using the URL specified in the argument */
		Player player = Manager.createPlayer(url);
		/* create a new JTabbedPane to hold the control components */
		jtp = new JTabbedPane();
		getContentPane().add(jtp);

		/* get the control component associated with the Player instance */
		controlComponent = player.getControlComponent();

		/* check if the control component was obtained successfully */
		if ( controlComponent != null )
		jtp.addTab ("Control Component",controlComponent);
		else
		{
		status = new Label("No control component available");
		jtp.addTab("Error",status);
		}
		/* get the media specific controls using the getControls method */
		Controls controls[] = player.getControls();
		
		for ( int i=0;i<controls.length; i++ )
		{
			/* check if the control component for the Control object is available */
			if (controls[i]. getControlComponent() != null )
			jtp.addTab("Control"+i, controls[i].getControlComponent());
		}
	}
	catch(Exception e)
	{
		System.out.println(e);
	}
}
In the above code, the getControls method is used to obtain media-specific controls for the Player instance. Each Control object returned by the getControls method calls the getControlComponent method. If the returned Component object is not null, it is added to the tabbed pane.

Submit "How To Implement User Interface For Media Components Using JMF API?" to Digg Submit "How To Implement User Interface For Media Components Using JMF API?" to del.icio.us Submit "How To Implement User Interface For Media Components Using JMF API?" to StumbleUpon Submit "How To Implement User Interface For Media Components Using JMF API?" to Google

Tags: java
Categories
Java

Comments




Disclaimer: Users of techforum4u.com are responsible for ensuring that any material they post (article, blog posts, images or other mulitimedia content) does not violate or infringe upon the copyright, patent, trademark, or any personal or proprietary rights of any third party, and is posted with the permission of the owner of such rights.Anyone who violates these rules may have their access privileges removed without warning.