FileDocCategorySizeDatePackage
MediaPlayer.javaAPI DocJMF 2.1.1e64912Mon May 12 12:20:42 BST 2003javax.media.bean.playerbean

MediaPlayer

public class MediaPlayer extends Container implements Player, Externalizable
MediaPlayer encapsulates a player in a JavaBeansTM component. MediaPlayer implements the Player and Externalizable interfaces.

A MediaPlayer can be used as a full-featured Player with either the default Player controls or custom controls.

MediaPlayer Properties

The following bean properties are supported by MediaPlayer:

  • loop: Indicates whether or not the media will be played repeatedly.
  • media location: The location of the media to be played. The location can be either an absolute address such as http://xena/demo/media/Sample1.mov or an address relative to the codebase address such as media/Sample1.mov
  • name: The name of this MediaPlayer.
  • size and position: The size and position of this MediaPlayer.
  • volume: The audio volume as a number from 0 to 5, where 0 is muted and 5 is the loudest possible volume. The default value is 3.
  • show control panel: Indicates whether or not the video control panel is displayed.
  • show caching control: Indicates whether or not the caching control is displayed. The caching control shows the download progress.
  • fixed aspect ratio: Indicates whether or not the aspect ratio of the video is maintained when the visual component is resized.

Two additional properties can be set. These are not bean properties, but provide additional control over the presentation:

  • ZoomLevel: Can be set through the popup menu and via set and get methods. (Click the right mouse button over the media to bring up the popup menu.)
  • MediaLocationVisible: Can be set through get and set methods. The media location is not editable during runtime.

    Invoking MediaPlayer

    You can instantiate MediaPlayer directly or using a bean-enabled IDE tool such as NetObjects BeanBuilder. To instantiate MediaPlayer directly:

    ClassLoader cl = this.getClass().getClassLoader();
    MediaPlayer pb = (MediaPlayer)Beans.instantiate(cl,
    "javax.media.bean.playerbean.MediaPlayer");
    

Fields Summary
private PropertyChangeSupport
changes
private String
urlString
private MediaLocator
mrl
private URL
url
private AppletContext
mpAppletContext
private boolean
panelVisible
private boolean
cachingVisible
private boolean
fixedAspectRatio
private boolean
fitVideo
private boolean
looping
transient Player
player
transient Panel
panel
transient Panel
vPanel
transient Panel
newPanel
transient Component
visualComponent
transient Component
controlComponent
transient Component
cachingComponent
private transient int
controlPanelHeight
private transient int
urlFieldHeight
private int
preferredHeight
private int
preferredWidth
private int
state
private Vector
controlListeners
PopupMenu
zoomMenu
private URL
mpCodeBase
protected transient GainControl
gainControl
protected transient String
curVolumeLevel
protected transient float
curVolumeValue
protected transient String
curZoomLevel
protected transient float
curZoomValue
protected transient Time
mediaTime
private InternalControllerAdapter
selfListener
private long
contentLength
private boolean
fixtedFirstTime
private boolean
displayURL
private boolean
isPopupActive
private transient TextField
urlName
private transient visualMouseAdapter
mouseListen
Method
errMeth
Constructors Summary
public MediaPlayer()
Constructs a MediaPlayer with its main panel preparing for caching control events and the following visual display.

      
	super();
	setLayout(null);
	if (panel == null) {
	    panel = new Panel();
	    panel.setLayout(new BorderLayout());
	    panel.setVisible(false);
	    add("Center",panel);
	}
	   
    
Methods Summary
private voidFatal(java.lang.String name)


        
	// Use reflection to get at the Log.
	try {
	    if (errMeth == null) {
		Class cls = Class.forName("com.sun.media.Log");  
		Class params[] = new Class [] 
		{ Class.forName("java.lang.Object") };
		errMeth = cls.getMethod("error", params);
	    }
	    Object args[] = new Object [] { name };
	    errMeth.invoke(null, args);
	} catch (Throwable t) {
	    System.err.println(name);
	}
    
public voidaddController(javax.media.Controller n)

	try {
	    if (player != null) {
		player.addController(n);
	    }
	} catch (IncompatibleTimeBaseException e) {
	    Fatal(MediaPlayerResource.getString("PLAYER_NO_COMPATIBLE_TIME_BASE"));
	    return;
	}
    
public voidaddControllerListener(javax.media.ControllerListener listener)

	if (player != null) {
	    player.addControllerListener(listener);
	}
	if (!controlListeners.contains(listener))
	    controlListeners.addElement(listener);
    
private voidaddPopupMenu(java.awt.Component visual)
addPopupMenu(): popup menu for some preset scales of the visualComponent

param
Component visual: the visual component to add the popup menu to.

	MenuItem mi;
	ActionListener zoomSelect;

	zoomMenu = new PopupMenu("Zoom");
	zoomSelect = new popupActionListener();
	visual.add(zoomMenu);
	mi = new MenuItem("Scale 1:2");
	zoomMenu.add(mi);
	mi.addActionListener(zoomSelect);
	mi = new MenuItem("Scale 1:1");
	zoomMenu.add(mi);
	mi.addActionListener(zoomSelect);
	mi = new MenuItem("Scale 2:1");
	zoomMenu.add(mi);
	mi.addActionListener(zoomSelect);
	mi = new MenuItem("Scale 4:1");
	zoomMenu.add(mi);
	mi.addActionListener(zoomSelect);
	   
    
public voidaddPropertyChangeListener(java.beans.PropertyChangeListener c)
Adds a PropertyChangeListener to the listener list.

param
c The PropertyChangeListener to be added.

	changes.addPropertyChangeListener(c);
    
private floataspectRatio(float width, float height, int controllerHeight)
aspectRatio(): calculate the aspect Ratio according to the width, height and control component, MediaLocation text height if they exist

param
float width: width of panel. float height: height of panel. int controllerHeight: including height of control component and mediaLocation height

	return (width/((float) (height-controllerHeight)));
    
private voidcalculateSize()

        if ( player == null )
            return;
	debug("claculateSize");
	if (( visualComponent = player.getVisualComponent())!= null) {
	    //   visualComponent.setSize(visualComponent.getPreferredSize());    
	    preferredHeight =visualComponent.getPreferredSize().height; 
	    preferredWidth =visualComponent.getPreferredSize().width; 
	    
	}
	
	if (((( controlComponent = player.getControlPanelComponent()) != null)&& 
	     (isControlPanelVisible()))||(displayURL==true)) {
	    if ((controlComponent!=null)&& (isControlPanelVisible())) {
		controlPanelHeight = controlComponent.getPreferredSize().height;
		preferredHeight +=controlPanelHeight;
		if (preferredWidth ==0)
		    preferredWidth = 320;
		
	    }
	    if (displayURL==true) {
		urlFieldHeight = urlName.getPreferredSize().height;
		preferredHeight +=urlFieldHeight;
	    }
	    
	}
	
	if (visualComponent != null) {
	    Dimension vSize = visualComponent.getPreferredSize();
	    int totalHeight=0;
	    if (controlComponent != null) {
		totalHeight+=controlComponent.getPreferredSize().height;
	    }
	    if (displayURL==true) {
		totalHeight +=urlName.getPreferredSize().height;
	    }
	    
	    if ((  fixedAspectRatio==true) && (curZoomValue == 1.0)) {
		
		//compare the ratio of parent and panel, and get the smaller number
		
		if ((vSize.width!=0) &&(vSize.height!=0)) {
		    if (((float)getSize().width/(float)vSize.width) >=
			((float)(getSize().height-totalHeight)/
			 (float)(vSize.height))) {
			
			curZoomValue =  
			    ((float)(getSize().height-totalHeight)/
			     (float)(vSize.height));
		    } else {    
			curZoomValue = 
			    ((float)getSize().width/vSize.width);
		    }
		}
		if (curZoomValue <0.5)
		    curZoomValue=1;
		
	    }	
	    if (newPanel !=null)
                newPanel.setSize(visualComponent.getPreferredSize().width,
				 controlPanelHeight+urlFieldHeight);
	    
	} 	 
	
    
private voidcenter(java.awt.Container parent, java.awt.Panel comp, boolean fit, int dheight)
center(): This method moves the component to the center of parent container. If fixAspectRatio is specified, then the width and height will be adjusted accordingly.

param
parent parent container comp component to be added to parent fit if maintain Aspect Ratio dheight height of controlComponent

	int pwidth = parent.getSize().width;
	int pheight = parent.getSize().height;
  
	int width = comp.getSize().width;
	int height = comp.getSize().height;
	if (fit) {
	    float aspect = aspectRatio((float) width,(float) height, dheight);
	    if (width > pwidth) {
		height = (int) ((float)pwidth/aspect) + dheight;
		if (height > pheight) {
		    width = (int) (aspect*(pheight-dheight));
		    height = pheight;
		} else
		    width = pwidth;
		comp.setBounds(parent.getBounds().x,parent.getBounds().y,width,height);
	    } else if (height > pheight) {
		width = (int) (aspect*(pheight-dheight));
		height = pheight;
           	comp.setBounds(parent.getBounds().x,parent.getBounds().y,width,height);
	    }
	}
	comp.setLocation((pwidth/2)-(width/2), (pheight/2)-(height/2));
	comp.setSize( width,height);
    
public voidclose()

	if (player != null) {
	    panel.removeAll();
	    player.close();
	    player = null;
	} else {
	    return;
	}
    
public voiddeallocate()

	if (player != null) {
	    debug("in deallocate");
	    player.deallocate();
	} else {
	    return;
	   
	}
    
private voiddebug(java.lang.String s)

	//	  System.out.println(s);
    
private synchronized voiddoRealize()
doRealize(): internal function to get the visual, gain, control components and add them to the panel of bean. If fixedAspectRatio is set, it will check if Bean has more space to expand the visual component and calculate the zoom factor.

	debug("in doRealize");
	if (player==null) {
	    Fatal(MediaPlayerResource.getString("SHOULD NOT OCCUR"));
	    System.exit(-1);
	}
	gainControl = player.getGainControl();
	    
	if (gainControl !=null) {
	    float re=gainControl.setLevel(curVolumeValue);  
	}
	      
	if (( visualComponent = player.getVisualComponent())!= null) {
	    vPanel = new Panel();
	    vPanel.setLayout( new BorderLayout() );
	    panel.setVisible(false);
	    visualComponent.setVisible(false);
	    vPanel.add("Center", visualComponent);
	    panel.add("Center", vPanel);
	  
	    addComponentListener(new visualComponentAdapter(this));
	    addPopupMenu(visualComponent);
	    setPopupActive();
	}
      
	newPanel=new Panel();
	newPanel.setLayout(new BorderLayout());
	panel.add("South",newPanel);
	urlName = new TextField(10);
	urlName.setEditable(false);
      
	if (displayURL==true) {
	    urlName.setText(urlString);
	    newPanel.add("South",urlName);
	}
	        
	if ((( controlComponent = player.getControlPanelComponent()) != null)&& 
	    (isControlPanelVisible())) {

	    controlComponent.setVisible(false);
	    newPanel.add("North",controlComponent);
	}
		    
	calculateSize();
      
	if (visualComponent == null) {
	    if (controlComponent !=null)
		panel.setSize(controlComponent.getPreferredSize().width,
			      controlPanelHeight+urlFieldHeight );     
	    else
		panel.setSize(100,urlFieldHeight);
	  
	}	
	showVisual();
    
public javax.media.ControlgetControl(java.lang.String forName)

	if (player != null) {
	    return player.getControl(forName);
	} else {
	    return null;
	}
    
public java.awt.ComponentgetControlPanelComponent()

	if (player != null) {
	    return player.getControlPanelComponent();
	}
	return null;
    
public intgetControlPanelHeight()
Gets the height of the control Component for this MediaPlayer.

return
The control Component height as an integer.

	  
	if (isControlPanelVisible())
	    return controlPanelHeight;
	else
	    return 0;
    
public javax.media.Control[]getControls()

	if (player != null) {
	    return player.getControls();
	} else {
	    return new Control[0];
	}
    
public javax.media.TimegetDuration()

	if (player != null) {
	    return player.getDuration();
	} else {
	    return DURATION_UNKNOWN;
	}
    
public javax.media.GainControlgetGainControl()

	if (player != null) {
	    return player.getGainControl();
	}
	return null;
    
public java.lang.StringgetMediaLocation()
Gets the value of the media location property for this MediaPlayer.

return
A String that contains the media location.

	if (mrl !=null) {
	    return mrl.toString();
	} else {
	    return urlString;
	}
    
public intgetMediaLocationHeight()
Gets the height of the media-location text field for this MediaPlayer.

return
The height of the media location text field as an integer.

	  
	if (isMediaLocationVisible())
	    return urlFieldHeight;
	else
	    return 0;
    
protected javax.media.MediaLocatorgetMediaLocator(java.lang.String filename)
Gets a MediaLocator for this MediaPlayer that corresponds to the specified String.

param
filename A String that contains the media name from which to create the MediaLocator.
return
A MediaLocator that corresponds to the specified String.

	MediaLocator localml = null;
	
	if (filename.regionMatches(true, 0, "<codebase>", 0, 10)) {
	    try {
		if (mpCodeBase == null)
		    initSetCodeBase();
		localml = new MediaLocator( new URL(mpCodeBase, filename.substring(11)));
	    } catch (java.net.MalformedURLException e) {
		if (mpCodeBase != null ) {
		    log(MediaPlayerResource.getString("NO IMAGE:BAD_URL")+
			filename+" " + mpCodeBase);
		    urlString = " ";
		}
		return null;
	    }  
	} else {
	    localml = new MediaLocator(filename);
	}
   
	return localml;
    
public longgetMediaNanoseconds()
Gets the current media time in nanoseconds.

return
The current media time in nanoseconds.

	if (player != null) {
	    return player.getMediaNanoseconds();
	} else {
	    return Long.MAX_VALUE;
	}
    
public javax.media.TimegetMediaTime()

	if (player != null) {
	    return player.getMediaTime();
	} else {
	    return LATENCY_UNKNOWN;
	}
    
public booleangetPlaybackLoop()
Gets the loop property for this MediaPlayer. This property indicates whether the MediaPlayer should play the media stream repeatedly or stop when the end of media is reached.

return
true if loop is enabled, false if the media stream is to be played only once.

	return looping;
	    
    
public javax.media.PlayergetPlayer()
Gets the current Player for this MediaPlayer.

return
The Player that this MediaPlayer is currently using.

	return player;
    
public java.awt.DimensiongetPreferredSize()
Gets the dimensions of the preferred size.

return
A Dimension that represents the preferred size.

	return new Dimension(preferredWidth, preferredHeight);
    
public floatgetRate()

	if (player != null) {
	    return player.getRate();
	} else {
	    return 0.0f;
	}
    
public javax.media.TimegetStartLatency()

	if (player != null) {
	    return player.getStartLatency();
	} else {
	    return LATENCY_UNKNOWN;
	}
    
public intgetState()

	if (player != null) {
	    return player.getState();
	} else {
	    return Controller.Unrealized;
	}
    
public javax.media.TimegetStopTime()

	if (player != null) {
	    return player.getStopTime();
	} else {
	    return null;
	}
    
public javax.media.TimegetSyncTime()

	if (player != null) {
	    return player.getSyncTime();
	} else {
	    return LATENCY_UNKNOWN;
	}
    
public intgetTargetState()

	if (player != null) {
	    return player.getTargetState();
	} else {
	    return Controller.Unrealized;
	}
    
public javax.media.TimeBasegetTimeBase()

	if (player != null) {
	    return player.getTimeBase();
	} else {
	    return null;
	}
    
public java.awt.ComponentgetVisualComponent()

	if (player != null) {
	    return player.getVisualComponent();
	}
	return null;
    
public java.lang.StringgetVolumeLevel()
Gets the audio volume property for this MediaPlayer. The volume can range from zero to five, where zero is silence and five is the maximum volume.

return
A String that represents the audio volume. Possible values are "0", "1", "2", "3", "4", or "5".

	return this.curVolumeLevel;
    
public java.lang.StringgetZoomTo()
Gets the zoom property for this MediaPlayer. This property specifies a scale factor for the visual components.

return
A String that specifies the zoom factor. Possible values are Scale 1:2, Scale 1:1, Scale 2:1, and Scale 4:1.

	return this.curZoomLevel;
    
private voidinitSetCodeBase()
initSetCodeBase(): set codebase for relative media location.

	if (mpCodeBase!=null)
	    return;
	
	Container p = getParent();
	while (p!=null) {
	    if (p instanceof Applet) 
		break;
	    p = p.getParent();
	}
	if (p!=null) {
	    setCodeBase(((Applet)p).getCodeBase());
	    mpAppletContext = ((java.applet.Applet) p).getAppletContext();
	}
	
    
public booleanisCachingControlVisible()
Gets the caching control visibility property for this MediaPlayer. This property indicates whether or not the caching control is displayed at runtime. The caching control displays the download progress for media accessed over the network.

return
true if the control panel is displayed at runtime, false if it is not.

	return cachingVisible;
    
public booleanisControlPanelVisible()
Gets the control panel visibility property for this MediaPlayer. This property indicates whether or not the control panel is visible at runtime.

return
true if the control panel is visible at runtime, false if it is not.

	return panelVisible;
    
public booleanisFixedAspectRatio()
Gets the fixed aspect ratio property for this MediaPlayer. This property indicates whether or not the aspect ratio of the video is maintained when the visual component is resized.

return
A boolean value that indicates whether or not the aspect ratio is maintained. Returns true if it is, false if it is not.

	return fixedAspectRatio;
    
public booleanisMediaLocationVisible()
Gets the MediaLocationVisible property for this MediaPlayer.

return
true if the media location is visible at runtime, false if it is not.

	return displayURL;
    
public booleanisPlayBackLoop()
Gets the loop property for this MediaPlayer. This property indicates whether the MediaPlayer should play the media stream repeatedly or stop when the end of media is reached.

return
true if loop is enabled, false if the media stream is to be played only once.

	return looping;
    
private voidlog(java.lang.String name)

	// Use reflection to get at the Log.
	try {
	    if (errMeth == null) {
		Class cls = Class.forName("com.sun.media.Log");  
		Class params[] = new Class [] 
		{ Class.forName("java.lang.Object") };
		errMeth = cls.getMethod("comment", params);
	    }
	    Object args[] = new Object [] { name };
	    errMeth.invoke(null, args);
	} catch (Throwable t) {
	    System.err.println(name);
	}
    
public javax.media.TimemapToTimeBase(javax.media.Time t)

	try {
	    if (player != null) {
		return player.mapToTimeBase(t);
	    }
	} catch (ClockStoppedException e) {
	    log(MediaPlayerResource.getString("CALL_A_STOPPED_CLOCK"));
	}

	return LATENCY_UNKNOWN;
    
public voidprefetch()

	if (player != null) {
	    player.prefetch();
	} else {
	    return;
	}
    
public voidreadExternal(java.io.ObjectInput in)
Restores the contents of this object

param
in The stream that can read primitive and object data types.
exception
IOException If an IO error occurs while try to read the object.
exception
java.lang.ClassNotFoundException If no definition for the class can be found.

	//save the component state
	setBounds((Rectangle)in.readObject());
	setBackground((Color) in.readObject());
	setForeground((Color) in.readObject());
	setFont((Font) in.readObject());
	setVisible(in.readBoolean());
	setEnabled(in.readBoolean());
	//restore MediaPlayer state
	String n = (String)(in.readObject());
	if (n != null) {
	    mrl = new MediaLocator(n);
	}
	if (mrl !=null) {
	    try {
		setMediaLocator(mrl);
	    } catch (Exception e) { }
	}
	setMediaLocationVisible(in.readBoolean());
	panelVisible = in.readBoolean();
	cachingVisible = in.readBoolean();
	fixedAspectRatio = in.readBoolean();
	preferredHeight = in.readInt();
	preferredWidth = in.readInt();
	  
	//restore Player state if appropriate
	if (in.readBoolean()) {
	    int s = in.readInt();
	    int ts = in.readInt();
	    state = Unrealized;
	    if (s >= Realized) {
		long mt = in.readLong();
		long st = in.readLong();
		float r = in.readFloat();
		if (ts >= Prefetched) {
		    player.prefetch();
		    waitForState(Prefetched);
		} else if (ts >= Realized) {
		    player.realize();
		    waitForState(Realized);
		}
		player.setMediaTime(new Time(mt));
		player.setStopTime(new Time(st));
		player.setRate(r);
		float l = in.readFloat();
		if (l != -1.0F) {
		    GainControl g = player.getGainControl();
		    if (g != null) {
			boolean mute = in.readBoolean();
			g.setLevel(l);
			g.setMute(mute);
		    } else {
			in.readBoolean();
		    }
		}
		    
		if (ts >= Started) {
		    player.start();
		}
	    }
	}
	invalidate();
	validate();
	  	  
    
public voidrealize()

	if (player != null) {
	    player.realize();
	} else {
	    return;
	}
    
public voidremoveController(javax.media.Controller old)

	if (player != null) {
	    player.removeController(old);
	}
    
public voidremoveControllerListener(javax.media.ControllerListener listener)

	if (player != null) {
	    player.removeControllerListener(listener);
	}
	if (controlListeners.contains(listener)) {
	    controlListeners.removeElement(listener);
	}
    
public voidremovePropertyChangeListener(java.beans.PropertyChangeListener c)
Removes a PropertyChangeListener from the listener list.

param
c The PropertyChangeListener to be removed.

	changes.removePropertyChangeListener(c);
    
public voidrestoreMediaTime()
Restores the media time saved by saveMediaTime so that the video resumes from the time it was stoped.

	setMediaTime(mediaTime);
    
public voidsaveMediaTime()
Saves the media stop time to a variable.

	mediaTime = getMediaTime();
    
public voidsetBounds(int x, int y, int w, int h)
Resizes the visual Component, control Component, and urlName according to the specified dimensions.

param
x The x coordinate of the rectangle.
param
y The y coordinate of the rectangle.
param
w The width of the rectangle.
param
h The height of the rectangle.

	debug("setBounds "+x +" "+y+" "+w+" "+h+" ");
	super.setBounds(x,y,w,h);
	Dimension d = getSize();
	int pheight = d.height;
	int pwidth = d.width;
	int p = 0;
	int totalHeight = 0;
	  
	if ((urlName!=null) &&(isMediaLocationVisible())) {
	    totalHeight = urlFieldHeight=urlName.getPreferredSize().height;
	    if ((pheight < 5) && (displayURL==true)) {
		pheight = 5;
	    }
	}    
	if ((controlComponent != null) && isControlPanelVisible()) {
	    controlPanelHeight=controlComponent.getPreferredSize().height;
	    totalHeight +=controlPanelHeight;
	   
	    if (d.width < 160)
		d.width = 160;
	    if ((pheight < 2) && (visualComponent != null))
		{
		    pheight += 2;
		}
	  
	}
	 
	if (visualComponent !=null) {
	    Dimension vSize = visualComponent.getPreferredSize();
	    if (fixedAspectRatio == true) {
		//compare the ratio of parent and panel, and get the smaller number
		if (((float)pwidth/(float)vSize.width) >=
		    ((float)(pheight-totalHeight)/
		     (float)(vSize.height-totalHeight)))
		    curZoomValue =  
			((float)(pheight-totalHeight)/
			 (float)(vSize.height-totalHeight));
		else    
		    curZoomValue = (float)pwidth/(float)vSize.width;
		
		if (curZoomValue <1.0)
		    curZoomValue=1;
		zoomTo(curZoomValue);
	    } else
		panel.setBounds(getBounds());
	   
	} else {
	    panel.setSize(getSize());
	    validate();
	}
	
    
public voidsetCachingControlVisible(boolean isVisible)
Sets the caching control visibility property for this MediaPlayer. This property indicates whether or not the caching control is displayed at runtime. The caching control displays the download progress for media accessed over the network.

param
isVisible A boolean value that indicates whether or not the caching control should be displayed at runtime. Set to true to display the control.

	if (cachingVisible != isVisible) {
	    boolean old = cachingVisible;
	    if (cachingComponent != null) {
		if (isVisible) {
		    panel.add("South", cachingComponent);
		} else {
		    panel.remove(cachingComponent);
		}
	    }
	    invalidate();
	    validate();
	    changes.firePropertyChange("cachingControlVisible", new Boolean(old),
				       new Boolean(cachingVisible));  
	    
	}
	cachingVisible = isVisible;
    
public voidsetCodeBase(java.net.URL cb)
Sets the codebase of the running applet.

param
cb The URL for the codebase of the currently running applet.

	mpCodeBase = cb;
    
public voidsetControlPanelVisible(boolean isVisible)
Sets the control panel visibility property for this MediaPlayer. This property indicates whether or not the control panel is displayed at runtime.

param
isVisible A boolean value that indicates whether or not the control panel should be displayed. Set to true to display the control panel.

	if (panelVisible != isVisible) {
	    boolean old=panelVisible;
	    if (controlComponent != null) {
		if (isVisible) {
		    panel.add("South", controlComponent);
		} else {
		    panel.remove(controlComponent);
		}
	    }
	    invalidate();
	    validate();
	    panelVisible = isVisible;
	    changes.firePropertyChange("controlPanelVisible", new Boolean(old),
				       new Boolean(panelVisible));
	}
	  
    
public voidsetDataSource(javax.media.protocol.DataSource ds)
Sets the DataSource for this MediaPlayer. This method creates a Player for the specified DataSource. If a Player already exists for this MediaPlayer, this method stops that Player and releases all of the resources it is using. Then a new Player is created with the specified DataSource. All controller listeners registered for the old Player are added to the listener list of the new Player.

param
ds A DataSource that identifies the media file to be presented by the MediaPlayer.

	try {
	    debug("setDataSource");
	    if (ds != null) {
		if (panel != null)
		    panel.removeAll();
		if (player != null) {
		    player.stop();
		    if (controlListeners.contains(selfListener))
		        controlListeners.removeElement(selfListener);
		}
	    }
	    if (urlName !=null) {
		if (ds.getLocator()!=null)
		    urlName.setText(ds.getLocator().toExternalForm());
		else
		    urlName.setText(""); 
		urlName.setFont(getFont());
	    }
	    try {
		player = javax.media.Manager.createPlayer(ds);
	    } catch (Exception e) {
		player = null;
		urlString = " ";
		Fatal(MediaPlayerResource.getString("UNABLE_CREATE_PLAYER")+e);
		return;
	    }
	    if (player==null) {
	        return;
	    }
	   
	    if (ds.getLocator()!=null) 
	        urlString = ds.getLocator().toExternalForm();
	    else
	        urlString = ""; 
	    player.addControllerListener(selfListener=new InternalControllerAdapter(this));
	    
	    if (!controlListeners.isEmpty()) {   
		for (int i=0;i<controlListeners.size();i++)
		    player.addControllerListener(
						 (ControllerListener)controlListeners.elementAt(i));
	    }
	   
	} catch (Exception e) {
	    mrl = null;
	    e.printStackTrace();
	    Fatal(MediaPlayerResource.getString("UNABLE_CREATE_PLAYER")+e);
	    return;
	}
    
public voidsetFixedAspectRatio(boolean isFixed)
Sets the fixed aspect ratio property for this MediaPlayer. This property indicates whether or not the aspect ratio of the video is maintained when the visual component is resized.

param
isFixed A boolean value that indicates whether or not the aspect ratio should be maintained. Set to true to maintain the aspect ratio.

	boolean old = fixedAspectRatio;
	fixedAspectRatio = isFixed;
	changes.firePropertyChange("fixedAspectRatio", new Boolean(old),
				   new Boolean(fixedAspectRatio));
    
public voidsetMediaLocation(java.lang.String location)
Sets the media location property for this MediaPlayer. This property specifies the location of the media file to be presented by the MediaPlayer. If a Player already exists for this MediaPlayer, this method stops that Player and releases all of the resources it is using. Then a new Player is created to present the specified media file. All controller listeners registered for the old Player are added to the listener list of the new Player.

param
location A String that contains the location of the media file.

   
	try {
	    String old = "";
	    if (mrl !=null) {
		old = mrl.toExternalForm();
		if (panel != null)
		    panel.removeAll();
		if (player != null) {
		    player.stop();
		    player.close();
		    panel.validate();
		    if (controlListeners.contains(selfListener))
		        controlListeners.removeElement(selfListener);
		}
	    }
	    urlString = location;
	    if ((mrl = getMediaLocator(location))==null) {
		//urlString = "";
		return;
	    }
	    try {
		player = javax.media.Manager.createPlayer(mrl);
	    } catch (Exception e) {
		player = null;
		urlString = " ";
		changes.firePropertyChange("mediaLocation",  location, old);
		Fatal(MediaPlayerResource.getString("UNABLE_CREATE_PLAYER")+e);
		return;
	    }
	   	    
	    if (player==null) {
		return;
	    }
      
	    if (urlName !=null) {
		urlName.setText(urlString);
		urlName.setFont(getFont());
	    }
	    player.addControllerListener(selfListener=new InternalControllerAdapter(this));
      
	    if (!controlListeners.isEmpty()) {   
		for (int i=0;i<controlListeners.size();i++)
		    player.addControllerListener(
						 (ControllerListener)controlListeners.elementAt(i));
	    }
	    changes.firePropertyChange("mediaLocation", old, location);
      
	} catch (Exception e) {
	    mrl = null;
	    e.printStackTrace();
	    Fatal(MediaPlayerResource.getString("UNABLE_CREATE_PLAYER")+e);
	    return;
	}
    
public voidsetMediaLocationVisible(boolean val)
Sets the MediaLocationVisible property for this MediaPlayer.

param
val A boolean that indicates whether or not the media location is visible. Set to true if the media location is visible at runtime, false if it is not.

	if (displayURL != val) {
	    if (urlName !=null) {
		if (val) { 
		    urlName.setText(urlString);
		    newPanel.add("South",urlName);
		} else {
		    newPanel.remove(urlName);
		}
	    }
	 	  
	    panel.validate();
	    validate();
	    displayURL = val;
	}
    
public voidsetMediaLocator(javax.media.MediaLocator locator)
Sets the MediaLocator for this MediaPlayer. This method creates a Player for the specified MediaLocator. If a Player already exists for this MediaPlayer, this method stops that Player and releases all of the resources it is using. Then a new Player is created with the specified MediaLocator. All controller listeners registered for the old Player are added to the listener list of the new Player.

param
locator A MediaLocator that identifies the media file to be presented by the MediaPlayer.

	try {
	    debug("setMediaLocator");
	    if (locator != null) {
		if (mrl !=null) {
		    if (panel != null)
		        panel.removeAll();
		    if (player != null) {
		        player.stop();
		        player.close();
		        if (controlListeners.contains(selfListener))
			    controlListeners.removeElement(selfListener);
		    }
		}
	    } else
		return;
	      
	    try {
		player = javax.media.Manager.createPlayer(locator);
	    } catch (NoPlayerException e) {
		player = null;
		urlString = " ";
		Fatal(MediaPlayerResource.getString("UNABLE_CREATE_PLAYER")+e);
		return;
	    } catch (java.io.IOException e) {
		player = null;
		urlString = " ";
		Fatal(MediaPlayerResource.getString("IO_EXCEPTION")+e);
		return;
	    }
	    
	    if (player==null) {
	        return;
	    }
	    urlString = locator.toExternalForm();
	    mrl = locator;
	    if (urlName !=null) {
		urlName.setText(urlString);
		urlName.setFont(getFont());
	    }
	    player.addControllerListener(selfListener=new InternalControllerAdapter(this));
	    
	    if (!controlListeners.isEmpty()) {
		for (int i=0;i<controlListeners.size();i++)
		    player.addControllerListener(
						 (ControllerListener)controlListeners.elementAt(i));
	    }
	   
	} catch (Exception e) {
	    url = null;
	    e.printStackTrace();
	    Fatal(MediaPlayerResource.getString("UNABLE_CREATE_PLAYER")+e);
	    return;
	}
    
public voidsetMediaTime(javax.media.Time now)

	if (player != null) {
	    player.setMediaTime(now);
	}
    
public voidsetPlaybackLoop(boolean val)
Sets the loop property for this MediaPlayer. This property indicates whether the MediaPlayer should play the media stream repeatedly or stop when the end of media is reached.

param
val The boolean value for the loop property. Specify true to enable looping, false if the media stream is to be played only once.

	boolean old = looping;
	looping = val;
	changes.firePropertyChange("playbackLoop", new Boolean(old),
				   new Boolean(looping));
    
public voidsetPlayer(javax.media.Player newPlayer)
Specifies an existing Player to use to present media for this MediaPlayer. If a Player already exists for this MediaPlayer, this method stops that Player and releases all of the resources it is using. All controller listeners registered for the old Player are added to the listener list of the new Player.

param
newPlayer The Player to use to present media data for this MediaPlayer.

	debug("setPlayer");
	    
	if (newPlayer == null)
	    return;
   
	if (newPlayer != null) {
	    if (panel != null)
		panel.removeAll();
	    if (player != null) {
		player.stop();
		if (controlListeners.contains(selfListener))
		    controlListeners.removeElement(selfListener);
	    }
	}
	player=newPlayer;
	urlString = "";
	player.addControllerListener(selfListener=new InternalControllerAdapter(this));
	switch(player.getState()) {
	case (Prefetched):
	    debug("player state prefetched ");  
	    break;
	case (Prefetching):
	    debug("player state prefetching ");  
	    break;
	case (Realized):
	    debug("player state Realized ");  
	    break;
	case (Realizing):
	    debug("player state  Realizing");  
	    break;
	case (Started):
	    debug("player state started ");  
	    break;
	case (Unrealized):
	    debug("player state Unrealized ");      
	    break;
	}
	if ((player.getState()==Realized) ||
	    (player.getState()==Prefetching)) 
	    doRealize();
	 
	if  ((player.getState()==Prefetched)  ||
	     (player.getState()==Started)) {
	    doRealize();
	    //doPrefetch();   
	} 	    
	if (!controlListeners.isEmpty()) {
	    for (int i=0;i<controlListeners.size();i++)
		player.addControllerListener(
					     (ControllerListener)controlListeners.elementAt(i));
	}
	   
    
public voidsetPopupActive(boolean isActive)
Specifies whether or not the Zoom Popup Menu is active. If setPopupActive is set to false, the popup menu won't be created.

param
isActive A boolean value that indicates whether or not the popup menu should be created. Set to true to activate the popup menu.

	if (isActive !=isPopupActive) {
	    isPopupActive = isActive; 
	    setPopupActive();
	}
    
private voidsetPopupActive()
Private class activate popup according to private variable isPopupActive.

	if (isPopupActive ==true)
	    visualComponent.addMouseListener( mouseListen= new visualMouseAdapter());
	else if(mouseListen!=null)
	    visualComponent.removeMouseListener(  mouseListen);
    
public floatsetRate(float factor)

	if (player != null) {
	    return player.setRate(factor);
	} else {
	    return 0.0f;
	}
    
public voidsetSource(javax.media.protocol.DataSource data)

	try {
	    if (player != null) {
		player.setSource(data);
	    }
	} catch (IOException e) {
	    Fatal(MediaPlayerResource.getString("IO_EXCEPTION")+e);
	    return;
	} catch (IncompatibleSourceException e) {
	    Fatal(MediaPlayerResource.getString("INCOMPATIBLE_SOURCE_EXCEPTION") + e);
	    return;
	}
    
public voidsetStopTime(javax.media.Time stopTime)

	if (player != null) {
	    player.setStopTime(stopTime);
	}
    
public voidsetTimeBase(javax.media.TimeBase master)

	try {
	    if (player != null) {
		player.setTimeBase(master);
	    }
	} catch (IncompatibleTimeBaseException e) {
	    Fatal(MediaPlayerResource.getString("INCOMPATIBLE_TIME_BASE")+e);
	    return;
	}
    
public voidsetVolumeLevel(java.lang.String volumeString)
Sets the audio volume property for this MediaPlayer. The volume can range from zero to five, where zero is silence and five is the maximum volume.

param
volumeString A String that represents the audio volume. Possible values are "0", "1", "2", "3", "4", or "5".

	debug("in setVolumeLevel");
	if (volumeString == null) {
	    return;
	}
	String old = curVolumeLevel;
	int level = Integer.parseInt(volumeString);
	curVolumeLevel = volumeString;
	curVolumeValue = level * 0.2f;

	if (gainControl != null)
	    gainControl.setLevel(curVolumeValue);
		
	changes.firePropertyChange("volumeLevel", old, curVolumeLevel);
	
    
public voidsetZoomTo(java.lang.String scale)
Sets the zoom property for this MediaPlayer. This property specifies a scale factor for the visual components. When zoom is called, the visual components are resized accordingly.

param
scale A String that specifies the zoom factor. Possible values are Scale 1:2, Scale 1:1, Scale 2:1, and Scale 4:1.

	debug("setZoomTo");
	curZoomLevel = scale;
	if (scale.trim().equals(MediaPlayerResource.getString("1:2"))) {
	    curZoomValue = 0.5f;
	} else if (scale.trim().equals(MediaPlayerResource.getString("1:1"))) {
	    curZoomValue = 1.0f;
	} else if (scale.trim().equals(MediaPlayerResource.getString("2:1"))) {
	    curZoomValue = 2.0f;
	} else if (scale.trim().equals(MediaPlayerResource.getString("4:1"))) {
	    curZoomValue = 4.0f;
	}

	fixtedFirstTime=false;
	zoomTo(curZoomValue);
    
private synchronized voidshowVisual()

	//debug(" doPrefetch");
	if (cachingComponent!=null) {
	    panel.remove(cachingComponent);
	    validate();
	}
	
	if ((visualComponent!=null) && 
	    ((fixedAspectRatio==true) || (fixtedFirstTime==false))) {
	    zoomTo(curZoomValue);
	} else {
	    panel.setSize(getSize());
	}
	panel.setVisible(true);
	if (visualComponent != null) {
	    visualComponent.setVisible(true);  
	}
	if ((controlComponent != null)&& (isControlPanelVisible())) {
	    controlComponent.setVisible(true); 
	}
	
	panel.validate();
	validate(); 
    
public voidstart()
Starts the MediaPlayer as soon as possible. If the MediaPlayer does not already have a Player, it creates one and then starts it.

	if (player != null) {
	    player.start();
	} else {
	    if (mrl ==null) {
		initSetCodeBase();
		mrl=getMediaLocator(urlString);
	    }
	    
	    if (mrl !=null) {
		try {
		    player = javax.media.Manager.createPlayer(mrl);
		    player.addControllerListener(selfListener =
						 new InternalControllerAdapter(this));
		    start();
		    //add original list to new player
		    if (controlListeners.size()>0) {   
			for (int i=0;i<controlListeners.size();i++)
			    player.addControllerListener(
							 (ControllerListener)controlListeners.elementAt(i));
		    }
		} catch (Exception e) {
		    player= null;
		    urlString = " ";
		    Fatal(MediaPlayerResource.getString("UNABLE_CREATE_PLAYER")+e);
		    return;
		}
	    } else 
		Fatal(MediaPlayerResource.getString("COULD_NOT_START_PLAYER"));
	    
	     
	}
    
public voidstop()

	if (player != null) {
	    player.stop();
	}
    
public voidstopAndDeallocate()
Stops the clock and deallocates the system resources used by this player.

	if (player != null) {
	    player.stop();
	}
    
public voidsyncStart(javax.media.Time at)

	debug("syncStart ");
	if (player != null) {
	    player.syncStart(at);
	}
    
public synchronized voidwaitForState(int s)
Ensures the ability to synchronously change state. Supports serialization.

param
s The state to wait for. The state constants are defined in Controller.
see
Controller#Unrealized
see
Controller#Realizing
see
Controller#Unrealized
see
Controller#Realized
see
Controller#Prefetching
see
Controller#Prefetched
see
Controller#Started

	while (state != s) {
	    try {
		wait(1000);
	    } catch (Exception e) {}
	}
    
public voidwriteExternal(java.io.ObjectOutput out)
Saves the contents of this object by calling the ObjectOutput writeObject method.

param
out The stream that can read primitive and object data types.
exception
IOException If an IO error occurs while attempting to save the object.

	//save the component state
	out.writeObject(getBounds());
	out.writeObject(getBackground());
	out.writeObject(getForeground());
	out.writeObject(getFont());
	out.writeBoolean(isVisible());
	out.writeBoolean(isEnabled());
	//save the MediaPlayer state
	
	if (mrl !=null) {
	    out.writeObject(mrl.toExternalForm());
	} else {
	    out.writeObject(null);
	}
	out.writeBoolean(displayURL);
	out.writeBoolean(panelVisible);  
	out.writeBoolean(cachingVisible); 
	out.writeBoolean(fixedAspectRatio);
	out.writeInt(preferredHeight);
	out.writeInt(preferredWidth);
	//save the Player state if appropriate
	if (player == null) {
	    out.writeBoolean(false);
	} else {
	    out.writeBoolean(true);
	    out.writeInt(player.getState());
	    out.writeInt(player.getTargetState());
	    if (player.getState() >= Realized) {
		out.writeLong(player.getMediaNanoseconds());
		out.writeLong(player.getStopTime().getNanoseconds());
		out.writeFloat(player.getRate());
		//we need to save Gain information:
		GainControl g;
		if ((g = player.getGainControl()) != null) {
		    out.writeFloat(g.getLevel());
		    out.writeBoolean(g.getMute());
		} else {
		    out.writeFloat(-1.0F);
		}
	    }
	}
    
private voidzoomTo(float z)
zoomTo(): method to handle the resize of the visual component of a player according to its input scale.

param
float z: the scale for resizing.

	debug("zoomTo "+z);
	int ddwidth=0;
	int ddheight=0;
	if ((visualComponent != null) && fitVideo) {
	    try {
		Dimension d=visualComponent.getPreferredSize();
		ddwidth = (int)(d.width * z);
		ddheight = (int)(d.height * z);
      
		int dheight=0;
		if ((controlComponent != null) && isControlPanelVisible())
		    dheight = controlComponent.getPreferredSize().height;
		if (displayURL ==true)
		    dheight += urlName.getPreferredSize().height;
		    
		if (newPanel!=null)
		    newPanel.setSize(ddwidth,dheight);
		panel.setSize(ddwidth , ddheight+dheight );	
      			    		      
		if ((fixedAspectRatio ==true) || 
		    ((fixedAspectRatio==false)&&(fixtedFirstTime==false)))  
		    center(this,panel,true,dheight);
		else
		    center(this,panel,false,dheight);
		  
		panel.validate();
  	
	    } catch (Exception e) {
		log(MediaPlayerResource.getString("UNABLE_TO_ZOOM")+e);
	    }
		   
	}