简体   繁体   English

从JAR播放.wav文件时遇到问题

[英]Trouble with playing .wav files from JAR

I'm having some strange trouble with playing a WAV file from a JAR. 从JAR播放WAV文件时遇到了一些奇怪的麻烦。
First, I can simply read it using ClassLoader when working in Eclipse. 首先,在Eclipse中工作时,我可以使用ClassLoader简单地读取它。 Everything works fine there. 那里一切正常。
Then I export my project to a JAR file. 然后,将项目导出到JAR文件。 But now it says that no such files exists although I can see it with an archivator; 但是现在它说,尽管我可以用一个存档器看到它,但是没有这样的文件。 for non-WAV files it works fine. 对于非WAV文件,它可以正常工作。
When I decided to export it to an external directory first the WAV file exports corrupted (while other files are not damaged, again). 当我决定先将其导出到外部目录时,WAV文件导出已损坏(而其他文件未再次损坏)。
What should be my problem then? 那我应该怎么办呢? I've made a research, but I couldn't find anything related to any trouble with WAV files or heavy files. 我进行了研究,但是找不到与WAV文件或沉重文件有关的任何问题。
How do I do it correctly and why does it work for small files but not the big ones (or sound files)? 如何正确执行该操作,为什么它适用于小文件,但不适用于大文件(或声音文件)?

Thank you for your awnsers. 谢谢您的遮阳篷。

EDIT: 编辑:
The package explorer in Eclipse: Eclipse中的软件包浏览器:
http://i.imgur.com/7TTyQit.png http://i.imgur.com/7TTyQit.png
The code used to actually get the file: 用于实际获取文件的代码:
private static MusicPlayer music = new MusicPlayer(new InputStream[]{MusicPlayer.class.getResourceAsStream("default/Final.wav")}, new InputStream[]{});
Finally, the exception: 最后,例外:
java.io.IOException: mark/reset not supported at java.util.zip.InflaterInputStream.reset(Unknown Source) at java.io.FilterInputStream.reset(Unknown Source) at com.sun.media.sound.SoftMidiAudioFileReader.getAudioInputStream(Unknown Source) at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source) at ru.windcorp.game.music.Music.run(Music.java:31) at ru.windcorp.game.music.MusicPlayer.playMenu(MusicPlayer.java:29) at ru.windcorp.game.GameMain.main(GameMain.java:152)

Don't make your AudioInputStream from an InputStream. 不要从InputStream中创建AudioInputStream。 Make it from a URL. 通过URL进行设置。

(1) URL's can "see" into jars. (1)URL可以“查看”到jar中。

(2) getAudioInputStream(InputStream inputStream) likely runs a Markability or Resetability test (or both) on the audio file when it is converted to an InputStream. (2)当将音频文件转换为InputStream时,getAudioInputStream(InputStream inputStream)可能会对音频文件运行Markability或Resetability测试(或两者)。 Most audio files seem to fail at this stage. 在此阶段,大多数音频文件似乎都失败了。

(3) getAudioInputStream(URL url) does NOT run a Markability test on the audio, thus circumventing the issue. (3)getAudioInputStream(URL url)不在音频上运行可标记性测试,从而避免了该问题。

Check out the API for the different input parameters of this method, for the AudioSystem object. 针对该AudioSystem对象,针对此方法的不同输入参数签出API。

Whoa! 哇! Why are you using com.sun.media.sound code? 为什么使用com.sun.media.sound代码? I think that has mostly been deprecated, hasn't it? 我认为这已经过时了,不是吗? SoftMidiAudioFileReader is no where to be found in the Java 7 SE API. 在Java 7 SE API中找不到SoftMidiAudioFileReader。 A slew of people are using this and generating errors. 大量的人正在使用它并产生错误。 Where did you get the suggestion to use this? 您从哪里得到使用此建议的?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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