I've written a code that read a WAV file (size is about 80 mb) and plays that. The problem is that sound plays badly (extreme lags). Can you please tell me what's the problem?
Here's my code:
(I call the doPlay
function inside a Jframe constructor)
private void doPlay(final String path) {
try {
stopPlay();
InputStream is = new FileInputStream(path);
InputStream bufferedIn = new BufferedInputStream(is);
AudioInputStream ais = AudioSystem.getAudioInputStream(bufferedIn);
AudioFormat format = ais.getFormat();
// this is the value of format.
// PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian
DataLine.Info info = new DataLine.Info(Clip.class, format);
clip = (Clip)AudioSystem.getLine(info);
clip.open(ais);
clip.start();
} catch (Exception e) {
stopPlay();
e.printStackTrace();
}
}