Horus Doc || Java GUI Reference || Doxygen's quick Index  

PlayingDirector Class Reference

This class can be used to control the playing of a video, in video based applications. More...

List of all members.

Public Methods

 PlayingDirector ()
 PlayingDirector (int nrFrames)
 PlayingDirector (int nrFrames, int frameInc, double frameRate)
int getNrFrames ()
void setNrFrames (int nrFrames)
 If the director is playing, setNrFrames stops it. More...

int getCurrentFrame ()
void setCurrentFrame (int fr)
 If the director is playing, setCurrentFrame stops it. More...

int getFrameInc ()
void setFrameInc (int frameInc)
 If the director is playing, setFrameInc stops it. More...

boolean isRealTime ()
void setRealTime (boolean rt)
 If the director is playing, setRealTime stops it. More...

double getFrameRate ()
void setFrameRate (double fps)
 If the director is playing, setFrameRate stops it. More...

void addPlayingObserver (PlayingObserver o)
void removePlayingObserver (PlayingObserver o)
boolean isRunning ()
void stop ()
 Stops the director. More...

void stop (boolean waitStop)
 Stops the director. More...

void play ()
void playFrom (int frameNr)
 If a PlayingObserver calls ths method, it can result in a deadlock. More...

void reset ()
 If a PlayingObserver calls ths method, it can result in a deadlock. More...

void step ()
void step (int frameInc)
void seekTo (int frameNr)
 Asks the director to jump to that frame. More...

void showCurrentFrame ()

Static Public Methods

PlayingDirector play (int nrFrames, PlayingObserver o)
 Easy way to create and start a PlayingDirector with just one observer. More...

void main (String[] args)


Detailed Description

This class can be used to control the playing of a video, in video based applications.

This class controls a thread that iterates over a sequence of numbers (say the frame numbers of a sequence). PlayingObservers can be registered to be notified each time a new number arrives. A PlayingObserver can be used, for instance, to display each frame.

A PlayingObserver is notified in two steps: prepareNewFrame and updateNewFrame. prepareNewFrame is called from the PlayingObserver thread, and updateNewFrame is called from the AWT event dispatch thread. If a PlayingObserver has to call some Swing related function (change the interface to display new frame), this call has to be done in the updateNewFrame: Swing is not thread-safe, and all the calls to Swing components have to be done from the AWT event dispatch thread. If the PlayingObserver has to perform some other processing not related to Swing (for instance, retrieve a new frame from the sequence), better put this call in prepareNewFrame. This will prevent the AWT event thread from being too busy and thus the GUI will react better to user input. PlayingObservers don't have to call SwingUtilities.invokeAndWait from prepareNewFrame. It will produce a dead-lock.

When the PlayingDirector reaches a new sequence number, it first calls the prepareNewFrame of all the PlayingObservers (sequentially), and then it tells the AWT event thread to call the updateNewFrame method of all the observers. Once all the updateNewFrame has been called, the PlayingDirector moves to a new sequence number.

start, stop and seek methods of observers are also called from AWT thread.

PlayingDirector assumes that all his public methods are called from the AWT event dispatch thread.


Constructor & Destructor Documentation

PlayingDirector::PlayingDirector   [inline]
 

00055 {
00056     this(0, 1, 25.0);
00057 }

PlayingDirector::PlayingDirector int    nrFrames [inline]
 

00060 {
00061     this(nrFrames, 1, 25.0);
00062 }

PlayingDirector::PlayingDirector int    nrFrames,
int    frameInc,
double    frameRate
[inline]
 

00065 {
00066     _nrFrames = nrFrames;
00067     _frameInc = frameInc;
00068     _frameRate = frameRate;
00069     _realTime = false;
00070     _curFrame = 0;
00071 
00072     _playing = false;
00073     _observers = new java.util.Vector();
00074 }


Member Function Documentation

PlayingDirector PlayingDirector::play int    nrFrames,
PlayingObserver    o
[inline, static]
 

Easy way to create and start a PlayingDirector with just one observer.

00079 {
00080     PlayingDirector director = new PlayingDirector(nrFrames);
00081     director.addPlayingObserver(o);
00082     director.play();
00083     return director;
00084 }

int PlayingDirector::getNrFrames   [inline]
 

00087 {
00088     return _nrFrames;
00089 }

void PlayingDirector::setNrFrames int    nrFrames [inline]
 

If the director is playing, setNrFrames stops it.

If a PlayingObserver calls ths method, it can result in a deadlock.

00095 {
00096     stop();
00097     _nrFrames = nrFrames;
00098 }

int PlayingDirector::getCurrentFrame   [inline]
 

00101 {
00102     return _curFrame;
00103 }

void PlayingDirector::setCurrentFrame int    fr [inline]
 

If the director is playing, setCurrentFrame stops it.

If a PlayingObserver calls ths method, it can result in a deadlock.

00109 {
00110     _frameSeeker.seek(fr);
00111     stop();
00112 }

int PlayingDirector::getFrameInc   [inline]
 

00115 {
00116     return _frameInc;
00117 }

void PlayingDirector::setFrameInc int    frameInc [inline]
 

If the director is playing, setFrameInc stops it.

If a PlayingObserver calls ths method, it can result in a deadlock.

00123 {
00124     _frameInc = frameInc;
00125 }

boolean PlayingDirector::isRealTime   [inline]
 

00128 {
00129     return _realTime;
00130 }

void PlayingDirector::setRealTime boolean    rt [inline]
 

If the director is playing, setRealTime stops it.

If a PlayingObserver calls ths method, it can result in a deadlock.

00136 {
00137     stop();
00138     _realTime = rt;
00139 }

double PlayingDirector::getFrameRate   [inline]
 

00142 {
00143     return _frameRate;
00144 }

void PlayingDirector::setFrameRate double    fps [inline]
 

If the director is playing, setFrameRate stops it.

If a PlayingObserver calls ths method, it can result in a deadlock.

00150 {
00151     stop();
00152     _frameRate = fps;
00153 }

void PlayingDirector::addPlayingObserver PlayingObserver    o [inline]
 

00156 {
00157     _observers.add(o);
00158 }

void PlayingDirector::removePlayingObserver PlayingObserver    o [inline]
 

00161 {
00162     _observers.remove(o);
00163 }

boolean PlayingDirector::isRunning   [inline]
 

00166 {
00167     return _playing;
00168 }

void PlayingDirector::stop   [inline]
 

Stops the director.

The call doesn't return till the director has stopped. If a PlayingObserver calls ths method, it can result in a deadlock.

00175 {
00176     stop(true);
00177 }

void PlayingDirector::stop boolean    waitStop [inline]
 

Stops the director.

if waitStop is true, the call doesn't return till the director has stopped. Otherwise, it asks the director to stop, but returns before it has stopped. If a PlayingObserver calls stop on the director, it has to use waitStop=false, otherwise it becomes a deadlock.

00186 {
00187     if(_playThread.isAlive()) {
00188         stopThread(waitStop);
00189         _playing = false;
00190     }
00191 }

void PlayingDirector::play   [inline]
 

00194 {
00195     if(!_playThread.isAlive()) {
00196         _playing = true;
00197         startThread(new PlayingThread());
00198     }
00199 }

void PlayingDirector::playFrom int    frameNr [inline]
 

If a PlayingObserver calls ths method, it can result in a deadlock.

00203 {
00204     setCurrentFrame(frameNr);
00205     play();
00206 }

void PlayingDirector::reset   [inline]
 

If a PlayingObserver calls ths method, it can result in a deadlock.

00210 {
00211     playFrom(0);
00212 }

void PlayingDirector::step   [inline]
 

00215 {
00216     step(_frameInc);
00217 }

void PlayingDirector::step int    frameInc [inline]
 

00220 {
00221     if(!_playThread.isAlive()) {
00222         _curFrame += frameInc;
00223         startThread(new PlayOnceThread());
00224     }
00225 }

void PlayingDirector::seekTo int    frameNr [inline]
 

Asks the director to jump to that frame.

When the call returns, it is not guaranteed that the director has already visited that frame. But it is guaranteed that the director will visit it eventually.

00232 {
00233     _frameSeeker.seek(frameNr);
00234 }

void PlayingDirector::showCurrentFrame   [inline]
 

00237 {
00238     step(0);
00239 }

void PlayingDirector::main String    args[] [inline, static]
 

00242 {
00243     PlayingDirector p = new PlayingDirector();
00244     p.setNrFrames(100);
00245     p.addPlayingObserver(PlayingObserverFactory.makeDebugObserver());
00246     p.addPlayingObserver(PlayingObserverFactory.makeDelayObserver(1000));
00247 
00248     p.play();
00249 
00250     /*try {
00251         Thread.sleep(1000);
00252     }catch(InterruptedException ex) {}
00253 
00254     System.out.println("stopping...");
00255     p.doStop();
00256     System.out.println("stop?");*/
00257 }


The documentation for this class was generated from the following file:
Generated on Mon Jan 27 15:11:24 2003 for JavaReference by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001