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

Java Sound problem with beep

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.3.0
    • client-libs



      Name: yyT116575 Date: 03/29/2001


      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

      When trying to use the new Java Sound api in JDK1.3, problems occur if attempts
      are made to use the system beep via Toolkit.getDefaultToolkit.beep() after
      playing an audio clip via Java Sound. To demonstrate run the following sample
      code provided below. You should notice that the system beep does not make any
      sound if Java Sound plays any clips beforehand. Comment out the clip open and
      start methods and you will then hear the system beep occur.

      Once I've played sound out via Java Sound, I no longer play any Windows system
      sounds until the JVM is shutdown. You can test this by running the SoundTest
      program I provided, leave the jvm open, then open the Sounds control panel
      and try to preview a sound. Windows will report an error back that "Windows cannot
      play the sound. Your sound card may be in use." If you close the SoundTest jvm,
      Windows can then preview sounds as normal. Seems Java Sound is hanging on
      to some hardware resource. Is there an api command to release it?

      Sample code:
      ------------

      package test;

      import javax.sound.sampled.*;
      import java.awt.*;
      import java.io.*;

      public class SoundTest {
        public static void main(String[] args) {
          new SoundTest();
        }
        public SoundTest() {
          try {
            AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new
      File("path to your audio wav file here"));
            Clip line = (Clip) AudioSystem.getLine(new DataLine.Info(Clip.class,
      audioInputStream.getFormat()));
            line.open(audioInputStream);
            line.start();
            line.drain();
            audioInputStream.close();
          }
          catch (Exception e) {e.printStackTrace();}
          Toolkit.getDefaultToolkit().beep();
        }
      }
      (Review ID: 119513)
      ======================================================================

            fbomerssunw Florian Bomers (Inactive)
            yyoungsunw Yung-ching Young (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: