0

I have a problem with playing a sound using OpenAL in Java (LWJGL). Whats worse is I have no idea what the error is telling me.

AL lib: ReleaseALC: 1 device not closed

Now I'm sure that the file location is correct but waveFile is returning a null, So the error is on line 8; when it's trying to get data from the waveFile.

FileInputStream fin = null;
try {
    fin = new FileInputStream("res/FancyPants.wav");
} catch (FileNotFoundException e) {
    e.printStackTrace();
}
WaveData waveFile = WaveData.create(fin);
AL10.alBufferData(buffer.get(0), waveFile.format, waveFile.data, waveFile.samplerate);
waveFile.dispose();

Many Thanks.

Iggy
  • 4,767
  • 5
  • 23
  • 34

1 Answers1

2

try wrapping the FileInputStream in a BufferedInputStream. Like this.

    FileInputStream fin = null;
    BufferedInputStream bin = null;
    try
    {
        fin = new FileInputStream("res/FancyPants.wav");
        bin = new BufferedInputStream(fin);
    }
    catch(FileNotFoundException e)
    {
        e.printStackTrace();
    }
    WaveData waveFile = WaveData.create(bin);
    AL10.alBufferData(buffer.get(0), waveFile.format, waveFile.data, waveFile.samplerate);

    waveFile.dispose();
tungsten
  • 329
  • 2
  • 10
  • That worked like a charm, thanks very much. I can now do it in one single line too `WaveData data = WaveData.create(new BufferedInputStream(new FileInputStream("res/FancyPants.wav")));` – Iggy Mar 04 '12 at 00:52