home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / VCafe / WDESAMPL.BIN / SoundArea.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-11-19  |  1.8 KB  |  60 lines

  1. import java.applet.AudioClip;
  2. import java.net.MalformedURLException;
  3. import java.net.URL;
  4.  
  5. class SoundArea extends ImageMapArea {
  6.    URL sound;
  7.    AudioClip soundData;
  8.    boolean hasPlayed;
  9.    boolean isReady = false;
  10.    long lastExit;
  11.    static final int HYSTERESIS = 1500;
  12.  
  13.    public void handleArg(String var1) {
  14.       try {
  15.          this.sound = new URL(super.parent.getDocumentBase(), var1);
  16.       } catch (MalformedURLException var2) {
  17.          this.sound = null;
  18.       }
  19.  
  20.       this.hasPlayed = false;
  21.    }
  22.  
  23.    public void getMedia() {
  24.       if (this.sound != null && this.soundData == null) {
  25.          this.soundData = super.parent.getAudioClip(this.sound);
  26.       }
  27.  
  28.       if (this.soundData == null) {
  29.          System.out.println("SoundArea: Unable to load data " + this.sound);
  30.       }
  31.  
  32.       this.isReady = true;
  33.    }
  34.  
  35.    public void enter() {
  36.       if (!this.isReady) {
  37.          super.parent.showStatus("Loading media file...");
  38.       } else {
  39.          long var1 = System.currentTimeMillis();
  40.          if (Math.abs(var1 - this.lastExit) < 1500L) {
  41.             this.hasPlayed = true;
  42.          } else {
  43.             if (!this.hasPlayed && this.soundData != null) {
  44.                this.hasPlayed = true;
  45.                this.soundData.play();
  46.             }
  47.  
  48.          }
  49.       }
  50.    }
  51.  
  52.    public void exit() {
  53.       if (this.hasPlayed) {
  54.          this.hasPlayed = false;
  55.          this.lastExit = System.currentTimeMillis();
  56.       }
  57.  
  58.    }
  59. }
  60.