I use tyring to write Java code that basically just plays a short .wav file - with βshortβ I mean a split second. (The file I'm using is located in /usr/share/sounds/generic.wav for those of you using Ubuntu.)
The problem is that I cannot figure out how to reproduce this sample correctly, i.e. in all my attempts, I can make my program play sound 4 out of 5 times or so, but not 100%.
This is what worked best in a standalone program:
File soundFile = new File("/usr/share/sounds/generic.wav"); Clip clip = AudioSystem.getClip(); AudioInputStream inputStream = AudioSystem.getAudioInputStream(soundFile); clip.open(inputStream); clip.start();
(Note that the code does not even call clip.stop ()). But even with this, if I run it a couple of times in a row, sooner or later it will be executed without any sound, but there are no exceptions.
Variations I tried:
1) Uploading an audio file to a byte array and transferring it to clip.open
2) Attaching a LineListener to a clip to wait for STOP events
plus a few random attempts, but so far I have not been able to create code that works every time.
I also know the following error: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4434125 , but I use Java 1.6, and the report states that everything should be fine with Java 1.5 or later.
Any ideas? Is this PulseAudio?
source share