home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 139 / dpcs0999.iso / Web / CFserver / data1.cab / Java / netscape / application / Sound.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-04-12  |  3.5 KB  |  114 lines

  1. package netscape.application;
  2.  
  3. import java.applet.AudioClip;
  4. import java.net.URL;
  5. import netscape.util.ClassInfo;
  6. import netscape.util.Codable;
  7. import netscape.util.CodingException;
  8. import netscape.util.Decoder;
  9. import netscape.util.Encoder;
  10.  
  11. public class Sound implements Codable {
  12.    String name;
  13.    AudioClip awtSound;
  14.    boolean shouldLoop;
  15.    static final String NAME_KEY = "name";
  16.  
  17.    public static synchronized Sound soundNamed(String var0) {
  18.       if (var0 != null && !var0.equals("")) {
  19.          Application var1 = Application.application();
  20.          Sound var2 = (Sound)var1.soundByName.get(var0);
  21.          if (var2 != null) {
  22.             return var2;
  23.          } else {
  24.             URL var3 = var1._appResources.urlForSoundNamed(var0);
  25.             var2 = soundFromURL(var3);
  26.             if (var2 == null) {
  27.                System.err.println("Unknown sound: " + var3);
  28.                return null;
  29.             } else {
  30.                var1.soundByName.put(var0, var2);
  31.                var2.name = var0;
  32.                return var2;
  33.             }
  34.          }
  35.       } else {
  36.          return null;
  37.       }
  38.    }
  39.  
  40.    public static Sound soundFromURL(URL var0) {
  41.       AudioClip var1 = AWTCompatibility.awtApplet().getAudioClip(var0);
  42.       Sound var2 = new Sound();
  43.       var2.awtSound = var1;
  44.       return var2;
  45.    }
  46.  
  47.    synchronized void nameSound(String var1, Sound var2) {
  48.       Application.application().soundByName.put(var1, var2);
  49.    }
  50.  
  51.    public String name() {
  52.       return this.name;
  53.    }
  54.  
  55.    public void setLoops(boolean var1) {
  56.       this.shouldLoop = var1;
  57.    }
  58.  
  59.    public boolean doesLoop() {
  60.       return this.shouldLoop;
  61.    }
  62.  
  63.    public void play() {
  64.       if (this.awtSound != null) {
  65.          if (this.shouldLoop) {
  66.             this.awtSound.loop();
  67.             return;
  68.          }
  69.  
  70.          this.awtSound.play();
  71.       }
  72.  
  73.    }
  74.  
  75.    public void stop() {
  76.       if (this.awtSound != null) {
  77.          this.awtSound.stop();
  78.       }
  79.  
  80.    }
  81.  
  82.    public String toString() {
  83.       return this.name != null ? "Sound(" + this.name + ")" : super.toString();
  84.    }
  85.  
  86.    public void describeClassInfo(ClassInfo var1) {
  87.       var1.addClass("netscape.application.Sound", 1);
  88.       var1.addField("name", (byte)16);
  89.    }
  90.  
  91.    public void encode(Encoder var1) throws CodingException {
  92.       if (this.name == null) {
  93.          throw new CodingException("An encoded Sound must have a name");
  94.       } else {
  95.          var1.encodeString("name", this.name);
  96.       }
  97.    }
  98.  
  99.    public void decode(Decoder var1) throws CodingException {
  100.       this.name = var1.decodeString("name");
  101.       if (this.name == null) {
  102.          throw new CodingException("A decoded Sound must have a name");
  103.       } else {
  104.          Application var3 = Application.application();
  105.          URL var2 = var3._appResources.urlForSoundNamed(this.name);
  106.          this.awtSound = var3.applet.getAudioClip(var2);
  107.          this.nameSound(this.name, this);
  108.       }
  109.    }
  110.  
  111.    public void finishDecoding() throws CodingException {
  112.    }
  113. }
  114.