home *** CD-ROM | disk | FTP | other *** search
/ Print Shop Ensemble 3 / the-print-shop-ensemble-iii.iso / worldnet / disk2 / java.z / MOZ2_01.ZIP / netscape / applet / AppletAudioClip.class (.txt) next >
Encoding:
Java Class File  |  1996-03-08  |  2.0 KB  |  73 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.    AudioData data;
  17.    InputStream stream;
  18.  
  19.    public AppletAudioClip(URL url) {
  20.       InputStream in = null;
  21.  
  22.       try {
  23.          try {
  24.             URLConnection uc = url.openConnection();
  25.             uc.setAllowUserInteraction(true);
  26.             in = uc.getInputStream();
  27.             this.data = (new AudioStream(in)).getData();
  28.          } finally {
  29.             if (in != null) {
  30.                in.close();
  31.             }
  32.  
  33.          }
  34.  
  35.       } catch (IOException var9) {
  36.          this.data = null;
  37.       }
  38.    }
  39.  
  40.    public synchronized void play() {
  41.       this.stop();
  42.       if (this.data != null) {
  43.          this.stream = new AudioDataStream(this.data);
  44.          AudioPlayer.player.start(this.stream);
  45.       }
  46.  
  47.    }
  48.  
  49.    public synchronized void loop() {
  50.       this.stop();
  51.       if (this.data != null) {
  52.          this.stream = new ContinuousAudioDataStream(this.data);
  53.          AudioPlayer.player.start(this.stream);
  54.       }
  55.  
  56.    }
  57.  
  58.    public synchronized void stop() {
  59.       if (this.stream != null) {
  60.          AudioPlayer.player.stop(this.stream);
  61.  
  62.          try {
  63.             this.stream.close();
  64.          } catch (IOException var1) {
  65.          }
  66.       }
  67.    }
  68.  
  69.    public String toString() {
  70.       return this.getClass().toString() + "[" + this.url + "]";
  71.    }
  72. }
  73.