home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1998 January / PCO0198.ISO / 1&1 / java.z / java_301 / sun / audio / AudioPlayer.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-10-20  |  1.9 KB  |  48 lines

  1. package sun.audio;
  2.  
  3. import java.io.InputStream;
  4.  
  5. public class AudioPlayer extends Thread {
  6.    private AudioDevice devAudio;
  7.    public static final AudioPlayer player = CreateAudioPlayer();
  8.  
  9.    private static AudioPlayer CreateAudioPlayer() {
  10.       SecurityManager.setScopePermission();
  11.       return new AudioPlayer();
  12.    }
  13.  
  14.    private static ThreadGroup getAudioThreadGroup() {
  15.       ThreadGroup g;
  16.       for(g = Thread.currentThread().getThreadGroup(); g.getParent() != null && g.getParent().getParent() != null; g = g.getParent()) {
  17.       }
  18.  
  19.       return g;
  20.    }
  21.  
  22.    private AudioPlayer() {
  23.       super(getAudioThreadGroup(), "Audio Player");
  24.       this.devAudio = AudioDevice.device;
  25.       SecurityManager.setScopePermission();
  26.       ((Thread)this).setPriority(10);
  27.       ((Thread)this).setDaemon(true);
  28.       SecurityManager.resetScopePermission();
  29.       ((Thread)this).start();
  30.    }
  31.  
  32.    public synchronized void start(InputStream in) {
  33.       this.devAudio.openChannel(in);
  34.       this.notify();
  35.    }
  36.  
  37.    public synchronized void stop(InputStream in) {
  38.       this.devAudio.closeChannel(in);
  39.    }
  40.  
  41.    public void run() {
  42.       this.devAudio.open();
  43.       this.devAudio.play();
  44.       this.devAudio.close();
  45.       System.out.println("audio player exit");
  46.    }
  47. }
  48.