简体   繁体   中英

Java Application won`t play sound

I wrote a program to play a bird sound. I got no errors when launching it but there was no sound. I'm running Netbeans IDE. Any ideas or solutions?

Here is my code:

package JavaFactoryPatternExample;


import java.io.File;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;

public class TutorialSound {
public static void main(String[] args ){
    File Bird = new File("JavaFactoryPatternExample.sounds/bird.WAV");
    PlaySound(Bird);
}

 static void PlaySound(File Sound){
    try{
        Clip clip = AudioSystem.getClip();
        clip.open(AudioSystem.getAudioInputStream(Sound));
        clip.start();

        Thread.sleep(clip.getMicrosecondLength()/1000);
    }catch(Exception e){

    }
}
}

Make sure that the file is in the same directory as the java program and that you have named it correctly. The file name seems odd.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM