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 = CreateAudioPlayer();
-
- private static AudioPlayer CreateAudioPlayer() {
- SecurityManager.setScopePermission();
- return 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;
- SecurityManager.setScopePermission();
- ((Thread)this).setPriority(10);
- ((Thread)this).setDaemon(true);
- SecurityManager.resetScopePermission();
- ((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);
- }
-
- public void run() {
- this.devAudio.open();
- this.devAudio.play();
- this.devAudio.close();
- System.out.println("audio player exit");
- }
- }
-