home *** CD-ROM | disk | FTP | other *** search
- package sun.audio;
-
- import java.io.InputStream;
-
- public class AudioPlayer extends Thread {
- private AudioDevice devAudio;
- public static final AudioPlayer player = new AudioPlayer();
-
- private static ThreadGroup getAudioThreadGroup() {
- ThreadGroup g;
- for(g = Thread.currentThread().getThreadGroup(); g.getParent() != null && g.getParent().getParent() != null; g = g.getParent()) {
- }
-
- return g;
- }
-
- private AudioPlayer() {
- super(getAudioThreadGroup(), "Audio Player");
- this.devAudio = AudioDevice.device;
- ((Thread)this).setPriority(10);
- ((Thread)this).setDaemon(true);
- ((Thread)this).start();
- }
-
- public synchronized void start(InputStream in) {
- this.devAudio.openChannel(in);
- this.notify();
- }
-
- public synchronized void stop(InputStream in) {
- this.devAudio.closeChannel(in);
- }
-
- private synchronized void waitForData() throws InterruptedException {
- this.devAudio.close();
- this.wait();
- this.devAudio.open();
- }
-
- public void run() {
- if (this.devAudio.openChannels() == 0) {
- try {
- this.waitForData();
- } catch (InterruptedException var1) {
- this.devAudio.closeStreams();
- return;
- }
- }
-
- this.devAudio.open();
- this.devAudio.play();
- this.devAudio.close();
- System.out.println("audio player exit");
- }
- }
-