Wave Trouble

I have trouble playing a wave in a java application. Here is the code:

import java.io.;
import java.applet.
;
import java.net.*;

public class PlayVariousMusicFiles{
private static AudioClip testClip;
private static URL testUrl;

public static void main(String args[]){
    String fileName="arf.wav";
    SoundTest(fileName);
    testClip.loop();
}

public static void SoundTest(String fileName){
    try{
     
		testUrl = new URL("file://H:/arf.wav");

// Get current directory name, and build URL
testClip=Applet.newAudioClip(testUrl);
testClip.play();
System.out.println(testUrl.toString());
System.out.println(“Should play”);
}catch(Exception e){
System.out.println(e.toString());
}
}

All I hear is a “poof” sound.

Your application might exit before the sound is finished playing.

Can you give me step-by-step instructions to fix it?

testClip.play(); just starts the clip playing, it doesn’t wait for it to finish. Add a Thread.sleep(clipDurtionInMilliseconds); after you call play(); that way the application won’t exit before the audio finishes playing.

Try this:

[quote]import java.io.;
import java.applet.
;
import java.net.*;

public class PlayVariousMusicFiles{
private static AudioClip testClip;
private static URL testUrl;

public static void main(String args[]){
    String fileName="arf.wav";
    SoundTest(fileName);
    testClip.loop();

    boolean running = true;
    while(running) {
    }
}

public static void SoundTest(String fileName){
    try{
     
     testUrl = new URL("file://H:/arf.wav");

// Get current directory name, and build URL
testClip=Applet.newAudioClip(testUrl);
testClip.play();
System.out.println(testUrl.toString());
System.out.println(“Should play”);
}catch(Exception e){
System.out.println(e.toString());
}
}
[/quote]
This will make the application run forever until the window is closed or Ctrl-C is pressed (Windows).