You are currently offline, waiting for your internet to reconnect

Your browser is out-of-date

You need to update your browser to use the site.

Update to the latest version of Internet Explorer

How To Playing a .WAV file in Java

This article was previously published under Q179850
SUMMARY
The Applet and AudioClip class only play .AU files. Microsoft offers twosolutions to play .WAV files when using the Microsoft virtual machine.

The Microsoft SDK for Java 2.0 and later includes a sample,DirectX3\dSound, demonstrating how to use DirectSound to play .WAV filesfrom a URL. It is also possible to use the Winmm class to play a .WAV filefrom the local drive, although your program must be trusted.
MORE INFORMATION
The sample code below demonstrates how to use the Winmm class to play a.WAV file. This sample requires you place a .WAV file in the currentdirectory and name the file "sound.wav".

Sample Code

import com.ms.win32.Winmm;import com.ms.win32.wins;public class PlayWav {  public static void main(String args[])  {    WavAudio ac = new WavAudio("sound.wav");    System.out.println("Looping sound...");    ac.loop();    try {      Thread.sleep(20000);    } catch (Exception e) {    }    System.out.println("stoping audio.");    ac.stop();  }}class WavAudio {  String wavFile=null;  public WavAudio(String file) {    wavFile=file;  }  public void stop() {    Winmm.PlaySound(null,0,       wins.SND_ASYNC|wins.SND_FILENAME|wins.SND_NOWAIT);  }  public void play() {    stop();    Winmm.PlaySound(wavFile,0,      wins.SND_ASYNC|wins.SND_FILENAME|wins.SND_NOWAIT);  }  public void loop() {    Winmm.PlaySound(wavFile,0,      wins.SND_ASYNC|wins.SND_LOOP|wins.SND_FILENAME|wins.SND_NOWAIT);  }}				
REFERENCES
For more information please see the Microsoft SDK for Java documentation,available at http://www.microsoft.com/mscorp/java/

For additional information, please see the following article in theMicrosoft Knowledge Base:
178707 Unable to play .Wav file from Applet or Audio Clip
audio .wav winmm
Properties

Article ID: 179850 - Last Review: 11/14/2005 09:24:00 - Revision: 4.2

  • Microsoft Software Development Kit for Java 2.02
  • Microsoft Software Development Kit for Java 3.2
  • Microsoft Software Development Kit for Java 2.01
  • Microsoft Software Development Kit for Java 2.02
  • Microsoft Software Development Kit for Java 3.0
  • Microsoft Software Development Kit for Java 3.1
  • Microsoft Java Virtual Machine
  • kbhowto KB179850
Feedback
microsoft.com/c.gif?DI=4050&did=1&t="> var varCustomerTracking = 1; var Route = "76500"; var Ctrl = ""; document.write(" ')[0].appendChild(m);" onload="var m=document.createElement('meta');m.name='ms.dqp0';m.content='false';document.getElementsByTagName('head')[0].appendChild(m);" src="http://c1.microsoft.com/c.gif?"> >>