- Have a class (probably your frame ) implement the ControllerListener
interface:
class MyFrame extends JFrame implements ControllerListener { ...
- Tell the player that the frame will listen for controller events:
player.addControllerListener(this);
- Override The controllerUpdate() method that the frame inherits from
the ControllerListener:
public void controllerUpdate(ControllerEvent e) { ...
- In the body of the controllerUpdate() method, you can test the
particular instance of the ControllerEvent to track the state of the
player. Sample code would look like: (Note: "instanceof" is a keyword, not
a method.)
if (e instanceof EventType)
- Here are some examples of event types that you could substitute in
place of EventType: (See the JMF state
model page for further explanation of the states.)
- RealizeCompleteEvent: Realizing is done, player is now in
'realized' state. This means it knows about the media file's
meta-information.
- PrefetchCompleteEvent: As with realize, we are done prefetching
(buffering) the media.
- StartEvent: The user hit the "play" button, or we called
player.start().
- StopByRequestEvent: Pause button hit by user.
- EndOfMediaEvent: Done playing the file.