开发者

Java clip.play hangs on 3rd invocation

开发者 https://www.devze.com 2023-01-21 00:07 出处:网络
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

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( );
    开发者_StackOverflow}catch (java.net.MalformedURLException malex){
        Logger.log(malex);
    }

No exception or error is reported.


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);

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

0

精彩评论

暂无评论...
验证码 换一张
取 消