JDK-7002619 : Incorrect return value of SourceDataLine.getLongFramePosition().
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.sound
  • Affected Version: 6u22,8,9
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: linux
  • CPU: x86
  • Submitted: 2010-11-24
  • Updated: 2021-07-13
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Relates :  
Description
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 ----------

Comments
EVALUATION cannot reproduce on ububtu 32bit, need to try on 64 bit when get the environment. The issue like a duplicate of 6986718 - ALSA reports underrun and JavaSound returns cached value (actually a number of samples written to the buffer, which in the case is "endingPosition")
11-04-2011