tags:

views:

25

answers:

1

I'm running a java (Netbeans) application on Ubuntu 10.10. The following code plays the sound correctly the first two times it is invoked. On the third invocation, the application hangs and I have to kill the process. Any ideas?

try {
        String path = ApplicationContext.getInstance().getAppDirectory();
        java.net.URL url = new java.net.URL("file:"+path+"my.wav");
        java.applet.AudioClip clip = java.applet.Applet.newAudioClip(url);
        clip.play( );
    }catch (java.net.MalformedURLException malex){
        Logger.log(malex);
    }

No exception or error is reported.

A: 

debugging with strace was getting really complex. I ended up taking the easy way out. Here's my solution.

java.io.InputStream in = new java.io.FileInputStream(path+"my.wav"); sun.audio.AudioStream as = new sun.audio.AudioStream(in); sun.audio.AudioPlayer.player.start(as);

(Sorry, I'm not sure what the problem is with the code formatting above. I pasted the code 4 different ways and none of them were formatted correctly.)

Unfortunately, this is not a good solution because: warning: sun.audio.AudioStream is internal proprietary API and may be removed in a future release.

MountainX