home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1998 January / PCO0198.ISO / browser / net_linx / java40.jar / netscape / applet / AppletAudioClip.class (.txt) next >
Encoding:
Java Class File  |  1997-11-03  |  2.0 KB  |  87 lines

  1. package netscape.applet;
  2.  
  3. import java.applet.AudioClip;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.net.URL;
  7. import java.net.URLConnection;
  8. import sun.audio.AudioData;
  9. import sun.audio.AudioDataStream;
  10. import sun.audio.AudioPlayer;
  11. import sun.audio.AudioStream;
  12. import sun.audio.ContinuousAudioDataStream;
  13.  
  14. public class AppletAudioClip implements AudioClip {
  15.    URL url;
  16.    private AudioData data;
  17.    InputStream stream;
  18.  
  19.    public AppletAudioClip(URL var1) {
  20.       this.url = var1;
  21.    }
  22.  
  23.    protected void init() {
  24.       if (this.data == null) {
  25.          InputStream var1 = null;
  26.  
  27.          try {
  28.             try {
  29.                SecurityManager.enablePrivilege("UniversalConnect");
  30.                URLConnection var4 = this.url.openConnection();
  31.                var4.setAllowUserInteraction(true);
  32.                var1 = var4.getInputStream();
  33.                SecurityManager.revertPrivilege();
  34.                this.data = (new AudioStream(var1)).getData();
  35.             } finally {
  36.                if (var1 != null) {
  37.                   var1.close();
  38.                }
  39.  
  40.             }
  41.  
  42.          } catch (IOException var8) {
  43.             this.data = null;
  44.          }
  45.       }
  46.    }
  47.  
  48.    public AppletAudioClip(byte[] var1) {
  49.       this.data = new AudioData(var1);
  50.    }
  51.  
  52.    public synchronized void play() {
  53.       this.init();
  54.       this.stop();
  55.       if (this.data != null) {
  56.          this.stream = new AudioDataStream(this.data);
  57.          AudioPlayer.player.start(this.stream);
  58.       }
  59.  
  60.    }
  61.  
  62.    public synchronized void loop() {
  63.       this.init();
  64.       this.stop();
  65.       if (this.data != null) {
  66.          this.stream = new ContinuousAudioDataStream(this.data);
  67.          AudioPlayer.player.start(this.stream);
  68.       }
  69.  
  70.    }
  71.  
  72.    public synchronized void stop() {
  73.       if (this.stream != null) {
  74.          AudioPlayer.player.stop(this.stream);
  75.  
  76.          try {
  77.             this.stream.close();
  78.          } catch (IOException var1) {
  79.          }
  80.       }
  81.    }
  82.  
  83.    public String toString() {
  84.       return this.getClass().toString() + "[" + this.url + "]";
  85.    }
  86. }
  87.