FileDocCategorySizeDatePackage
StateHelper.javaAPI DocJMF 2.1.1e2717Mon May 12 12:20:28 BST 2003None

StateHelper

public class StateHelper extends Object implements javax.media.ControllerListener

Fields Summary
Player
player
boolean
configured
boolean
realized
boolean
prefetched
boolean
eom
boolean
failed
boolean
closed
Constructors Summary
public StateHelper(Player p)

    
       
	player = p;
	p.addControllerListener(this);
    
Methods Summary
public voidclose()

	synchronized (this) {
	    player.close();
	    while (!closed) {
		try {
		    wait(100);
		} catch (InterruptedException ie) {
		}
	    }
	}
	player.removeControllerListener(this);
    
public booleanconfigure(int timeOutMillis)

	long startTime = System.currentTimeMillis();
	synchronized (this) {
	    if (player instanceof Processor)
		((Processor)player).configure();
	    else
		return false;
	    while (!configured && !failed) {
		try {
		    wait(timeOutMillis);
		} catch (InterruptedException ie) {
		}
		if (System.currentTimeMillis() - startTime > timeOutMillis)
		    break;
	    }
	}
	return configured;
    
public synchronized voidcontrollerUpdate(ControllerEvent ce)

	if (ce instanceof RealizeCompleteEvent) {
	    realized = true;
	} else if (ce instanceof ConfigureCompleteEvent) {
	    configured = true;
	} else if (ce instanceof PrefetchCompleteEvent) {
	    prefetched = true;
	} else if (ce instanceof EndOfMediaEvent) {
	    eom = true;
	} else if (ce instanceof ControllerErrorEvent) {
	    failed = true;
	} else if (ce instanceof ControllerClosedEvent) {
	    closed = true;
	} else {
	    return;
	}
	notifyAll();
    
public booleanplayToEndOfMedia(int timeOutMillis)

	long startTime = System.currentTimeMillis();
	eom = false;
	synchronized (this) {
	    player.start();
	    while (!eom && !failed) {
		try {
		    wait(timeOutMillis);
		} catch (InterruptedException ie) {
		}
		if (System.currentTimeMillis() - startTime > timeOutMillis)
		    break;
	    }
	}
	return eom && !failed;
    
public booleanprefetch(int timeOutMillis)

	long startTime = System.currentTimeMillis();
	synchronized (this) {
	    player.prefetch();
	    while (!prefetched && !failed) {
		try {
		    wait(timeOutMillis);
		} catch (InterruptedException ie) {
		}
		if (System.currentTimeMillis() - startTime > timeOutMillis)
		    break;
	    }
	}
	return prefetched && !failed;
    
public booleanrealize(int timeOutMillis)

	long startTime = System.currentTimeMillis();
	synchronized (this) {
	    player.realize();
	    while (!realized && !failed) {
		try {
		    wait(timeOutMillis);
		} catch (InterruptedException ie) {
		}
		if (System.currentTimeMillis() - startTime > timeOutMillis)
		    break;
	    }
	}
	return realized;