FULL PRODUCT VERSION :
java version "1.6.0_18"
OpenJDK Runtime Environment (IcedTea6 1.8.2) (6b18-1.8.2-4ubuntu2)
OpenJDK 64-Bit Server VM (build 16.0-b13, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux desktop-ubuntu-64bits 2.6.32-25-generic #45-Ubuntu SMP Sat Oct 16 19:52:42 UTC 2010 x86_64 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
When playing a sound, the method SourceDataLine.getLongFramePosition() reports that the line has already reached the last frame of sampled data, when actually it is still being played by the system.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the snipped provided below to play a sound file.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The sounds plays completely, and then program execution terminates.
In Oracle's JDK 1.6.22 this is precisely what happens, and the output when playing a short sound is:
ending position: 0
ending position: 8544
frame position: 60
Line is still working.
frame position: 8544
ACTUAL -
In OpenJDK 6's JVM that comes bundled with my Ubuntu box, the sound stops playing abruptly in the end, and the output is:
position: 0
ending position: 8544
frame position: 8544
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.File;
import javax.sound.sampled.*;
public class Test {
public static void main(String[] args) throws Exception {
// *** edit this path to a WAV file in your system ***
File soundFile = new File("/arquivo/dados/workspace_3.6.1/test_JavaSound/src/campainha.wav");
AudioInputStream audioStream = AudioSystem.getAudioInputStream(soundFile);
AudioFormat format = audioStream.getFormat();
SourceDataLine line = AudioSystem.getSourceDataLine(format);
line.open(format);
line.start();
byte[] data = new byte[128000];
int bytesRead;
long endingPosition = line.getLongFramePosition();
System.out.println("ending position: " + endingPosition);
while((bytesRead = audioStream.read(data)) != -1) {
endingPosition += line.write(data, 0, bytesRead) / format.getFrameSize();
System.out.println("ending position: " + endingPosition);
}
while(line.getLongFramePosition() < endingPosition) {
System.out.println("frame position: " + line.getLongFramePosition());
System.out.println("Line is still working.");
Thread.sleep(1000);
}
System.out.println("frame position: " + line.getLongFramePosition());
if(line.isRunning()) {
line.stop();
}
line.close();
audioStream.close();
}
}
---------- END SOURCE ----------