FileDocCategorySizeDatePackage
Handler.javaAPI DocJMF 2.1.1e8385Mon May 12 12:20:58 BST 2003com.sun.media.content.application.x_jmx

Handler

public class Handler extends BasicPlayer
MediaPlayer extends BasicPlayer and uses MediaEngine to play media.

Fields Summary
Player[]
players
Player
master
boolean[]
realized
Vector
locators
ControllerListener
listener
boolean
playersRealized
Object
realizedSync
private boolean
closed
private boolean
audioEnabled
private boolean
videoEnabled
String
sessionError
private Container
container
Constructors Summary
public Handler()



      
        framePositioning = true;
    
Methods Summary
protected booleanaudioEnabled()

	return audioEnabled;
    
protected voidcompleteRealize()

	state = Realized;
	super.completeRealize();
    
protected java.awt.ComponentcreateVisualContainer(java.util.Vector visuals)

	Boolean hint = (Boolean) Manager.getHint(Manager.LIGHTWEIGHT_RENDERER);
	
	if (container == null) {
	    if (hint == null || hint.booleanValue() == false) {
		container = new HeavyPanel(visuals);
	    } else {
		container = new LightPanel(visuals);
	    }
	
	    container.setLayout( new FlowLayout() );
	    container.setBackground(Color.black);
	    
	    for (int i = 0; i < visuals.size(); i++) {
		Component c = (Component)visuals.elementAt(i);
		container.add(c);
		c.setSize(c.getPreferredSize());
	    }
	}
	
	return container;
    
protected voiddoClose()


	closed = true;

	synchronized (realizedSync) {
	    realizedSync.notify();
	}

	stop();

	super.doClose();
    
protected voiddoDeallocate()

	synchronized (realizedSync) {
	    realizedSync.notify();
	}
    
protected booleandoRealize()


       

        super.doRealize();

	MediaLocator ml = null;

        try {
            
	    players = new Player[locators.size()];
	    realized = new boolean[locators.size()];

	    for (int i = 0; i < locators.size(); i++) {
		ml = (MediaLocator)locators.elementAt(i);
		players[i] = Manager.createPlayer(ml);
		players[i].addControllerListener(listener);
		realized[i] = false;
		players[i].realize();
	    }

        } catch (Exception e) {
            Log.error(sessionError + ml);
	    processError = sessionError + ml;
            return false;
        }

	// dont realize this meta player until our player is realized
	try{
	    synchronized (realizedSync) {
		while (!playersRealized && !isInterrupted() && !closed)
		    realizedSync.wait();
	    }
	} catch (Exception e) {}

	// If realize is being interrupted, return failure from realize.
	if (closed || isInterrupted()) {
	    resetInterrupt();
	    processError = "Realize interrupted";
	    return false;
	}

	try {
	    master = players[0];
	    for (int i = 1; i < players.length; i++) {
		master.addController(players[i]);
	    }
	} catch (IncompatibleTimeBaseException e) {
	    processError = "AddController failed";
	    return false;
	}

	manageController(master);

        return true;
    
protected voiddoStart()

	super.doStart();
    
protected voiddoStop()

	super.doStop();
    
protected javax.media.TimeBasegetMasterTimeBase()

	return master.getTimeBase();
    
public java.awt.ComponentgetVisualComponent()

    
       
	Vector visuals = new Vector(1);

	for( int i = 0; i < players.length; i++) {
	    Component comp= players[i].getVisualComponent();

	    if( comp != null) {
		visuals.addElement( comp);
	    }
	}

	if( visuals.size() == 0) {
	    return null;
	} else if( visuals.size() == 1) {
	    return (Component) visuals.elementAt( 0);
	} else {
	    return createVisualContainer( visuals);
	}
    
private voidinvalidateComp()

	controlComp = null;
	controls = null;
    
private voidsendMyEvent(javax.media.ControllerEvent e)

	super.sendEvent(e);
    
public voidsetSource(javax.media.protocol.DataSource source)

	super.setSource(source);

	if (!(source instanceof PullDataSource))
	    throw new IncompatibleSourceException();

	PullSourceStream pss[] = ((PullDataSource)source).getStreams();

	if (pss.length != 1)
	    throw new IncompatibleSourceException();

	source.start();

	int len = (int)pss[0].getContentLength(); 

	if (len == SourceStream.LENGTH_UNKNOWN)
	    throw new IncompatibleSourceException();

	byte barray[] = new byte[len];
	String content;

	try {

	    len = pss[0].read(barray, 0, len);
	    content = new String(barray);

	} catch (Exception e) {
	    throw new IncompatibleSourceException();
	}

	char ch;
	int start = 0, idx;
	int size = content.length();
	String str;
	String relPath = null;

	ch = content.charAt(start);

	while (start < size) {

	    while (ch == ' " || ch == '\n") {
		start++;
		if (start >= size)
		    break;
		ch = content.charAt(start);
	    }

	    if (start >= size)
		break;
	
	    idx = start;

	    do {
		idx++;
		if (idx >= size)
		    break;
		ch = content.charAt(idx);
	    } while (ch != '\n");

	    str = content.substring(start, idx);

	    if (str.indexOf(':") == -1) {

	        // Probably didn't specify a protocol or
		// absolute path here.
		// We'll assume it's relative path and use
		// the first part of the media locator to
		// generate the name.

		if (relPath == null) {
		    MediaLocator loc = source.getLocator();
		    if (loc == null)
			throw new IncompatibleSourceException();
		    relPath = loc.toString();
		    int i = relPath.lastIndexOf('/");
		    if (i < 0)
			i = relPath.lastIndexOf(File.separator);
		    relPath = relPath.substring(0, i + 1);
		}
		str = relPath + str;
	    }

	    locators.addElement(new MediaLocator(str));
	    start = idx;
	}

	if (locators.size() < 1) 
	    throw new IncompatibleSourceException();
    
public voidupdateStats()

	for (int i = 0; i < players.length; i++) {
	    if (players[i] != null)
		((BasicPlayer)players[i]).updateStats();
	}
    
protected booleanvideoEnabled()

	return videoEnabled;