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

Something wrong with the close() method of AudioInputStream class

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P4 P4
    • None
    • 1.3.0
    • client-libs



      Name: rlT66838 Date: 03/27/2000


      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc1-T)
      Java HotSpot(TM) Client VM (build 1.3.0rc1-S, mixed mode)

      I open some wav files. For each I create a Clip object. I play all the Clips,
      after that I close all the clips and the streams. But some streams didn't close
      untill I stop the application. So during the running, I tried to delete all the
      wav files, but I was unable to delete ONLY the last wav file (ussualy when I
      have an odd number of wav files - when I have even number of files everything
      was OK).
      So I think is something wrong with the close() method of AudioInputStream. I
      have to mention that I didn't catch any exception.

      So basicaly I've a class MyAudioClip :



      public class MyAudioClip {
      Object currentSound;
      AudioInputStream mystream;

      public MyAudioClip(Object object) {
      if (object instanceof File) {
                   try {
             currentSound = AudioSystem.getAudioInputStream((File) object);
      }
      catch(Exception e1) {
                      currentSound = null;
      }
      }
      if (currentSound instanceof AudioInputStream) {
                   try {
                      AudioInputStream stream = (AudioInputStream) currentSound;
      AudioFormat format = stream.getFormat();

      DataLine.Info info = new DataLine.Info(
                                            Clip.class,
                                            stream.getFormat(),
                                            ((int) stream.getFrameLength() *
                                            format.getFrameSize()));

      Clip clip = (Clip) AudioSystem.getLine(info);
      mystream = stream;
                      clip.open(stream);
      currentSound = clip;
      } catch (Exception ex) {
      ex.printStackTrace();
      currentSound = null;
      }
      }
      }


      public void play() {
      if (currentSound instanceof Clip) {
                    Clip clip = (Clip) currentSound;
      clip.start();

             while (clip.isActive()) {
      }
      clip.stop();
      //clip.close();
      }
      // currentSound = null;
      }

      public void close() {
      if (currentSound instanceof Clip) {
      try {
      Clip clip = (Clip) currentSound;

      clip.close();
              mystream.close();
      }
      catch (Exception ex) {
      ex.printStackTrace();
      currentSound = null;
      }

      }
      currentSound = null;
      }







      public class Playback {

      public static void main(String args[]) {

                  File mywavfile1 = new File("c:\\xxx\\1-welcome.wav");
      File mywavfile2 = new File("c:\\xxx\\chord.wav");
      File mywavfile3 = new File("c:\\xxx\\ding.wav");


      MyAudioClip myclip1 = new MyAudioClip(mywavfile1);
      MyAudioClip myclip2 = new MyAudioClip(mywavfile2);
      MyAudioClip myclip3 = new MyAudioClip(mywavfile3);


      myclip1.play();
      myclip2.play();
      myclip3.play();



      myclip1.close();
      myclip2.close();
      myclip3.close();



      for(int i=0;i<100000;i++)
      for(int j=0;j<30000;j++);

      System.out.println("The End");


      System.exit(0);
      }
      }
      (Review ID: 102936)
      ======================================================================

            fbomerssunw Florian Bomers (Inactive)
            rlewis Roger Lewis (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: