I'm successfully playing sounds in a Java (1.5) applet game using the following code:
// get an available clip to play it
Clip clip = null;
for (Clip clipTemp : players) {
if (!clipTemp.isOpen()) {
clip = clipTemp;
break;
}
}
if (clip == null) {
// no available player found, don't play
return;
}
clip.open(audioFormat, audioByteData, 0, audioByteData.length);
clip.start();
(Players are a list of clips that I open at the start with the aim to reduce latency, a line listener closes the line when the stop event is retrieved.)
The problem I'm facing is intermittent delays of upto 1 second when playing a sound. This is pretty poor.
Is there any way to improve this? Are SourceDataLines
worth considering?