home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 129 / dpcs1198.iso / Internet / Compu / Win95 / MSIE302.LIB / MSIE302.EXE / ieakjava.exe / CLASSR.EXE / com / ms / applet / AppletAudioClip.class (.txt) next >
Encoding:
Java Class File  |  1997-01-31  |  2.0 KB  |  85 lines

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