home *** CD-ROM | disk | FTP | other *** search
- package netscape.applet;
-
- import java.applet.AudioClip;
- import java.io.IOException;
- import java.io.InputStream;
- import java.net.URL;
- import java.net.URLConnection;
- import sun.audio.AudioData;
- import sun.audio.AudioDataStream;
- import sun.audio.AudioPlayer;
- import sun.audio.AudioStream;
- import sun.audio.ContinuousAudioDataStream;
-
- public class AppletAudioClip implements AudioClip {
- URL url;
- AudioData data;
- InputStream stream;
-
- public AppletAudioClip(URL url) {
- InputStream in = null;
-
- try {
- try {
- URLConnection uc = url.openConnection();
- uc.setAllowUserInteraction(true);
- in = uc.getInputStream();
- this.data = (new AudioStream(in)).getData();
- } finally {
- if (in != null) {
- in.close();
- }
-
- }
-
- } catch (IOException var9) {
- this.data = null;
- }
- }
-
- public synchronized void play() {
- SecurityManager.setScopePermission();
- this.stop();
- if (this.data != null) {
- this.stream = new AudioDataStream(this.data);
- AudioPlayer.player.start(this.stream);
- }
-
- }
-
- public synchronized void loop() {
- SecurityManager.setScopePermission();
- this.stop();
- if (this.data != null) {
- this.stream = new ContinuousAudioDataStream(this.data);
- AudioPlayer.player.start(this.stream);
- }
-
- }
-
- public synchronized void stop() {
- SecurityManager.setScopePermission();
- if (this.stream != null) {
- AudioPlayer.player.stop(this.stream);
-
- try {
- this.stream.close();
- } catch (IOException var1) {
- }
- }
- }
-
- public String toString() {
- return this.getClass().toString() + "[" + this.url + "]";
- }
- }
-