[英]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.
我试图从项目内部的名为sound的文件夹中访问文件。 I also marked the project as root resource folder.
我还将该项目标记为根资源文件夹。
URL url = this.getClass().getResource("./sound/ac.wav"); 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
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.