Best web hosting site - /** * Method fireAnimationEvent. */ private void fireAnimationEvent()
/** * Method fireAnimationEvent. */ private void fireAnimationEvent() { // If segment == null we have reached the end of the list if (segment != null) { // Fetch end time from segment and convert to msec int end = (int) (1000 * segment.getFeatures().getFloat(”end”)); // Get phoneme from segment String phone = segment.getFeatures().getString(”name”); // Advance in segment list segment = segment.getNext(); // Create new AnimationEvent object AnimationEvent e = new AnimationEvent(end, phone); // Send it to all AnimationListener objects Iterator iter = listeners.iterator(); while (iter.hasNext()) { AnimationListener listener = (AnimationListener) iter.next(); listener.processAnimationEvent(e); } // Create new timer that expires at the end time // of the current phoneme. timer = new Timer(end - currentTime, this); timer.setRepeats(false); timer.setCoalesce(false); timer.start(); // Update current time currentTime = end; } } update() The whole animation is started when a START line event arrives. The Animator receives such events because it is registered as a LineListener with the Java Sound System. /** * @see javax.sound.sampled.LineListener#update(LineEvent) */ public void update(LineEvent event) { if (event.getType().equals(LineEvent.Type.START)) { // Audio output has started start animation, too. // Fire first event fireAnimationEvent(); } } /** * @see java.lang.Object#toString() */ public String toString() { return “Animator”; } } 80 Chapter 5