FileDocCategorySizeDatePackage
DelayedSoundArea.javaAPI DocSun JDK 1.4.2 Example3961Thu May 12 00:35:29 BST 2005None

DelayedSoundArea

public class DelayedSoundArea extends ImageMapArea
This ImageArea Class will play a sound each time the user enters the area. It is different from SoundArea in that it accepts a delay (in tenths of a second) before it plays the sound. If the mouse leaves the area before the time delay, the sound is not played. This allows you to have one piece of audio when the button is "hit" via SoundArea and another if the user stays on the button.
author
Chuck McManis
version
1.13, 01/23/03

Fields Summary
URL
sound
The URL of the sound to be played.
AudioClip
soundData
boolean
hasPlayed
int
delay
int
countDown
Constructors Summary
Methods Summary
public booleananimate()
This method is called every animation cycle if there are any active animating areas.

return
true if this area requires further animation notifications

	if (entered && ! hasPlayed) {
	    if (countDown > 0) {
		countDown--;
		return true;
	    }
	    hasPlayed = true;
	    if (soundData != null) {
	        soundData.play();
	    }
	}
	return false;
    
public voidenter()
The highlight method plays the sound in addition to the usual graphical highlight feedback.

	hasPlayed = false;
	countDown = delay;
	parent.startAnimation();
    
public voidgetMedia()

	if (sound != null) {
	    soundData = parent.getAudioClip(sound);
	}
	if (soundData == null) {
	    System.out.println("DelayedSoundArea: Unable to load data "+sound);
	}
    
public voidhandleArg(java.lang.String arg)
The argument is the URL of the sound to be played. This method also sets this type of area to be non-terminal.

	Thread soundLoader;
	StringTokenizer st = new StringTokenizer(arg, ", ");
	
	delay = Integer.parseInt(st.nextToken());
	try {
	    sound = new URL(parent.getDocumentBase(), st.nextToken());
	} catch (MalformedURLException e) {
	    sound = null;
	}