Workaround for UnsupportedAudioFileException?

亡梦爱人 提交于 2019-12-02 08:14:58

问题


I'm in a very early stage of writing a small music/rhythm game in Java (via Slick framework, which in turns uses OpenAL, but that's probably irrelevant here). The game needs to read (and playback) several sound files in WAV format, but some of the files are throwing [javax.sound.sampled.UnsupportedAudioFileException] exceptions.

at javax.sound.sampled.AudioSystem.getAudioInputStream(AudioSystem.java:1102)
at org.newdawn.slick.openal.WaveData.create(WaveData.java:123)
at org.newdawn.slick.openal.SoundStore.getWAV(SoundStore.java:713)
at org.newdawn.slick.openal.SoundStore.getWAV(SoundStore.java:683)
at org.newdawn.slick.Sound.<init>(Sound.java:33)

The files can be played back just fine in Winamp or Foobar2000, so this means Java just don't recognize some variants of the file format. What are my options at this point?

Note: The files in question are user-supplied, so i cannot just convert them beforehand (using something like audacity). Any conversion steps must be done at runtime.


回答1:


One thing that needs to be recognized about WAV files are, is that it is a container format -- it can hold data in many different formats, including uncompressed PCM to MP3.

In this case, I am going to guess that the library that is being used is hooking into the Java Sound API, and the implementation of the API does not support the format of the data contained in the WAV file, leading to an UnsupportedAudioFileException exception.

The files can be played back just fine in Winamp or Foobar2000, so this means Java just don't recognize some variants of the file format.

The reason why Winamp and other programs can playback the WAV file is because it is probably using the Windows Audio Compression Manager or (if I understand correctly) DirectShow, which is used to manage different types of audio codecs.

Winamp itself does not need to know how to decode the audio data inside the WAV file; it asks ACM or DirectShow to return the raw audio data on which it can handle. (Or also possibly, the data is directly send to the audio output.)

What are my options at this point?

An alternative does seem to exist in the form of the Java Media Framework, which appears to have support many multimedia formats.

It says that it will hook into the Windows ACM when using the "JMF 2.1.1 Windows Performance Pack", so it might be able to playback the WAV files which can't be played back by the Java Sound API.



来源:https://stackoverflow.com/questions/2843847/workaround-for-unsupportedaudiofileexception

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!