简体   繁体   中英

wav audio not playing from a jar file created from intellij

This is the piece of the code that I used. I tried to access the file from the folder called sound which is inside my project. I also marked the project as root resource folder.

URL url = this.getClass().getResource("./sound/ac.wav");

File file = new File(url.toURI());

WavFile wavFile = WavFile.openWavFile(file);

AudioInputStream stream1 = AudioSystem.getAudioInputStream(file);

Pretty simple code to play sound file.

private void playSound() {
    try {
        InputStream inputStream = getClass().getResourceAsStream("/test1/bark.wav");
        AudioStream audioStream = new AudioStream(inputStream);
        AudioPlayer.player.start(audioStream);
    } catch (Exception e) {
      // handle exception
    }
}

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