我似乎无法弄清楚为什么我的音频文件无法播放。 音频文件是一个wav文件,只是。 我得到的错误是javax.sound.sampled.UnsupportedAudioFileException 。
public class MusicProgress { public static void main(String[] args) { // TODO Auto-generated method stub JFrame b = new JFrame(); FileDialog fd = new FileDialog(b, "Pick a file: ", FileDialog.LOAD); fd.setVisible(true); final File file = new File(fd.getDirectory() + fd.getFile()); //URI directory = new URI (fd.getDirectory() + fd.getFile()); try { AudioInputStream inputStream = AudioSystem.getAudioInputStream(file); AudioFormat audioFormat = inputStream.getFormat(); Clip clip = AudioSystem.getClip(); clip.open(inputStream); clip.start(); } catch (LineUnavailableException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (UnsupportedAudioFileException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }I can't seem to figure out why my audio file won't play. The audio file is a wav file and is just. The error i am getting is javax.sound.sampled.UnsupportedAudioFileException.
public class MusicProgress { public static void main(String[] args) { // TODO Auto-generated method stub JFrame b = new JFrame(); FileDialog fd = new FileDialog(b, "Pick a file: ", FileDialog.LOAD); fd.setVisible(true); final File file = new File(fd.getDirectory() + fd.getFile()); //URI directory = new URI (fd.getDirectory() + fd.getFile()); try { AudioInputStream inputStream = AudioSystem.getAudioInputStream(file); AudioFormat audioFormat = inputStream.getFormat(); Clip clip = AudioSystem.getClip(); clip.open(inputStream); clip.start(); } catch (LineUnavailableException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (UnsupportedAudioFileException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }最满意答案
Java不支持所有wav格式。 支持的最高质量是标准CD编码格式。 有了这些文件,你应该没问题。 该格式具有16位编码,44100 fps,小端,立体声。 您应该能够检查wav文件的属性并了解它是否匹配。
DAW越来越常见的是生成具有24位或32位编码或48000fps或92000fps的wav文件。
可以使用Audacity等工具将这些转换为“CD”编码规范。
Java does not support all wav formats. The highest quality supported is a standard CD encoding format. With those files, you should be okay. That format has 16-bit encoding, 44100 fps, little endian, stereo. You should be able to inspect the properties of your wav file and learn if it matches or not.
It is getting more and more common for DAWs to produce wav files that have 24-bit or 32-bit encoding, or 48000fps or 92000fps.
It is possible to convert these to the "CD" encoding spec with a tool such as Audacity.
更多推荐
发布评论