1

I am working on a maven project and need to play a .wav file to accompany a desktop alert. I have tested the .wav file on its own to make sure that it works and it does. I have imported it into my project structure and when it is in the source directory, it is 46 KB. When I perform mvn clean install on the project, the target directory that is generated contains the .wav file, but it is 87 kb there.

This is the error that I get: javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input file

I put in a logging statement to check the generated path in my log4j logs and the path is correct. This makes me think that the mvn clean install is modifying the format or contents of the .wav file, but I don't understand how and ultimately how to prevent it from happening.

Update

Here is a code snippet:

String filename = this.getClass().getResource("/audio/affirmative.wav").getPath();

logger.debug("wav file path: " + filename);

AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File(filename).getAbsoluteFile());

Clip clip = AudioSystem.getClip();
clip.open(audioInputStream);
clip.start();

Any ideas? Thanks in advance!

4

1 回答 1

2

您可能已将 wav 文件放在由 Maven 过滤的目录中(变量替换)。

解决方案:将二进制文件放在没有被过滤的目录中。

在我的项目中,我开始有 2 个资源目录:

  • src/main/resources:过滤
  • src/main/resources-bin:未过滤

您可以在此处查看我用作父 POM 的 POM 文件,以了解如何配置它: http ://search.maven.org/remotecontent?filepath=org/softsmithy/softsmithy-parent/2.2/softsmithy -parent-2.2.pom

或者,如果您愿意,也可以将其用作您自己的父 POM 的父级:

<parent>
    <groupId>org.softsmithy</groupId>
    <artifactId>softsmithy-parent</artifactId>
    <version>2.2</version>
</parent>

像这样,您将获得资源配置以及更多开箱即用的内容。

不过,请确保覆盖父 POM 中的所有项目特定设置。

您可以通过运行来检查这一点mvn help:effective-pom

于 2013-06-13T20:45:33.517 回答