开发者

Java clip.play hangs on 3rd invocation

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜