home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 April / DPPCPRO0499.ISO / April / Notes / 50b2wic.exe / DATA1.CAB / NotesProgramFilesJavaSupport / rt.jar / sun / applet / AppletAudioClip.class (.txt) next >
Encoding:
Java Class File  |  1998-04-23  |  2.0 KB  |  77 lines

  1. package sun.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 var1) {
  20.       InputStream var2 = null;
  21.  
  22.       try {
  23.          try {
  24.             URLConnection var5 = var1.openConnection();
  25.             var5.setAllowUserInteraction(true);
  26.             var2 = var5.getInputStream();
  27.             this.data = (new AudioStream(var2)).getData();
  28.          } finally {
  29.             if (var2 != null) {
  30.                var2.close();
  31.             }
  32.  
  33.          }
  34.  
  35.       } catch (IOException var9) {
  36.          this.data = null;
  37.       }
  38.    }
  39.  
  40.    public AppletAudioClip(byte[] var1) {
  41.       this.data = new AudioData(var1);
  42.    }
  43.  
  44.    public synchronized void play() {
  45.       this.stop();
  46.       if (this.data != null) {
  47.          this.stream = new AudioDataStream(this.data);
  48.          AudioPlayer.player.start(this.stream);
  49.       }
  50.  
  51.    }
  52.  
  53.    public synchronized void loop() {
  54.       this.stop();
  55.       if (this.data != null) {
  56.          this.stream = new ContinuousAudioDataStream(this.data);
  57.          AudioPlayer.player.start(this.stream);
  58.       }
  59.  
  60.    }
  61.  
  62.    public synchronized void stop() {
  63.       if (this.stream != null) {
  64.          AudioPlayer.player.stop(this.stream);
  65.  
  66.          try {
  67.             this.stream.close();
  68.          } catch (IOException var1) {
  69.          }
  70.       }
  71.    }
  72.  
  73.    public String toString() {
  74.       return this.getClass().toString() + "[" + this.url + "]";
  75.    }
  76. }
  77.