JDK-4431740 : Java Sound problem with beep
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.sound
  • Affected Version: 1.3.0
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_nt
  • CPU: x86
  • Submitted: 2001-03-29
  • Updated: 2002-10-31
  • Resolved: 2002-10-31
Related Reports
Relates :  
Description

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) 
======================================================================

Comments
EVALUATION ###@###.### 2002-10-30 Indeed the JDC comment is right. Close the clip with clip.close() and the sound card resources are released for other windows programs. For applets, however, there was such a problem that Applet.AudioClip didn't release the audio device and blocked a soundcard until the browser was closed. See bug 4302884.
11-06-2004