Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-5070081

REGRESSION: javax.sound.sampled.Clip loses position when stopped

    • b48
    • x86
    • windows_2000, windows_xp

        Name: jl125535 Date: 06/30/2004


        FULL PRODUCT VERSION :
        java version "1.5.0-beta3"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta3-b57)
        Java HotSpot(TM) Client VM (build 1.5.0-beta3-b57, mixed mode)

        REGRESSION : Last worked with
        java version "1.4.2"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
        Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)


        ADDITIONAL OS VERSION INFORMATION :
        Microsoft Windows 2000 [Version 5.00.2195]

        EXTRA RELEVANT SYSTEM CONFIGURATION :
        Creative SoundBlaster Live!

        A DESCRIPTION OF THE PROBLEM :
        If you call "stop()" on a Clip that is playing, the position of the Clip jumps.
        The subsequent starting position is arbirtary.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Start playing a Clip and then stop it using "stop()" before it ends.
        Call "start()" to resume playback.

        Run the example code supplied and use jre1.5 and see the results.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        I expected to hear the sound of "1 2 3 4"
        and a printout similar to:
        Clip length: 60912
        Position before stop: 21594
        Position after stop: 21595
        Position at end: 60912
        ACTUAL -
        I heard the sound "1 4 4" (may vary)
        and the following result was printed:
        Clip length: 60912
        Position before stop: 22083
        Position after stop: 44541
        Position at end: 77724


        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import java.net.URL;
        import javax.sound.sampled.AudioFormat;
        import javax.sound.sampled.AudioInputStream;
        import javax.sound.sampled.AudioSystem;
        import javax.sound.sampled.Clip;
        import javax.sound.sampled.DataLine;

        public class BugTest {
          public static void main(String[] args) throws Exception {
            // create a clip from a file
            AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new //URL("http://www.speech.kth.se/~mikaeln/1234.wav"));
        java.io.File("1234.wav"));
            AudioFormat audioFormat = audioInputStream.getFormat();
            DataLine.Info info = new DataLine.Info(Clip.class, audioFormat);
            Clip clip = (Clip)AudioSystem.getLine(info);
            clip.open(audioInputStream);
            audioInputStream.close();
            System.out.println("Clip length: " + clip.getFrameLength());
            clip.start(); // start playing
            Thread.sleep(1000); // wait a sec
            int pos = clip.getFramePosition(); // store the position
            System.out.println("Position before stop: " + pos);
            clip.stop(); // and then stop
        // clip.setFramePosition(pos); // set the position
            System.out.println("Position after stop: " + clip.getFramePosition());
            Thread.sleep(1000);
            clip.start(); // and start again
            while(clip.isRunning()); // wait for the sound to finish
            System.out.println("Position at end: " + clip.getFramePosition());
          }
        }

        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        Removing the comment for "clip.setFramePosition(pos);" in the supplied code fixes the bug.

        Release Regression From : tiger-beta2
        The above release value was the last known release where this
        bug was known to work. Since then there has been a regression.

        (Incident Review ID: 282073)
        ======================================================================

              amenkov Alex Menkov
              jleesunw Jon Lee (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: