home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1998 January / PCO0198.ISO / 1&1 / java.z / java_301 / netscape / applet / AppletAudioClip.class (.txt) next >
Encoding:
Java Class File  |  1996-10-20  |  2.1 KB  |  76 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.       SecurityManager.setScopePermission();
  42.       this.stop();
  43.       if (this.data != null) {
  44.          this.stream = new AudioDataStream(this.data);
  45.          AudioPlayer.player.start(this.stream);
  46.       }
  47.  
  48.    }
  49.  
  50.    public synchronized void loop() {
  51.       SecurityManager.setScopePermission();
  52.       this.stop();
  53.       if (this.data != null) {
  54.          this.stream = new ContinuousAudioDataStream(this.data);
  55.          AudioPlayer.player.start(this.stream);
  56.       }
  57.  
  58.    }
  59.  
  60.    public synchronized void stop() {
  61.       SecurityManager.setScopePermission();
  62.       if (this.stream != null) {
  63.          AudioPlayer.player.stop(this.stream);
  64.  
  65.          try {
  66.             this.stream.close();
  67.          } catch (IOException var1) {
  68.          }
  69.       }
  70.    }
  71.  
  72.    public String toString() {
  73.       return this.getClass().toString() + "[" + this.url + "]";
  74.    }
  75. }
  76.