home *** CD-ROM | disk | FTP | other *** search
- package netscape.application;
-
- import java.applet.AudioClip;
- import java.net.URL;
- import netscape.util.ClassInfo;
- import netscape.util.Codable;
- import netscape.util.CodingException;
- import netscape.util.Decoder;
- import netscape.util.Encoder;
-
- public class Sound implements Codable {
- String name;
- AudioClip awtSound;
- boolean shouldLoop;
- static final String NAME_KEY = "name";
-
- public static synchronized Sound soundNamed(String var0) {
- if (var0 != null && !var0.equals("")) {
- Application var1 = Application.application();
- Sound var2 = (Sound)var1.soundByName.get(var0);
- if (var2 != null) {
- return var2;
- } else {
- URL var3 = var1._appResources.urlForSoundNamed(var0);
- var2 = soundFromURL(var3);
- if (var2 == null) {
- System.err.println("Unknown sound: " + var3);
- return null;
- } else {
- var1.soundByName.put(var0, var2);
- var2.name = var0;
- return var2;
- }
- }
- } else {
- return null;
- }
- }
-
- public static Sound soundFromURL(URL var0) {
- AudioClip var1 = AWTCompatibility.awtApplet().getAudioClip(var0);
- Sound var2 = new Sound();
- var2.awtSound = var1;
- return var2;
- }
-
- synchronized void nameSound(String var1, Sound var2) {
- Application.application().soundByName.put(var1, var2);
- }
-
- public String name() {
- return this.name;
- }
-
- public void setLoops(boolean var1) {
- this.shouldLoop = var1;
- }
-
- public boolean doesLoop() {
- return this.shouldLoop;
- }
-
- public void play() {
- if (this.awtSound != null) {
- if (this.shouldLoop) {
- this.awtSound.loop();
- return;
- }
-
- this.awtSound.play();
- }
-
- }
-
- public void stop() {
- if (this.awtSound != null) {
- this.awtSound.stop();
- }
-
- }
-
- public String toString() {
- return this.name != null ? "Sound(" + this.name + ")" : super.toString();
- }
-
- public void describeClassInfo(ClassInfo var1) {
- var1.addClass("netscape.application.Sound", 1);
- var1.addField("name", (byte)16);
- }
-
- public void encode(Encoder var1) throws CodingException {
- if (this.name == null) {
- throw new CodingException("An encoded Sound must have a name");
- } else {
- var1.encodeString("name", this.name);
- }
- }
-
- public void decode(Decoder var1) throws CodingException {
- this.name = var1.decodeString("name");
- if (this.name == null) {
- throw new CodingException("A decoded Sound must have a name");
- } else {
- Application var3 = Application.application();
- URL var2 = var3._appResources.urlForSoundNamed(this.name);
- this.awtSound = var3.applet.getAudioClip(var2);
- this.nameSound(this.name, this);
- }
- }
-
- public void finishDecoding() throws CodingException {
- }
- }
-