无法播放音频文件(Can't get audio file to play)

编程入门 行业动态 更新时间:2024-10-26 14:28:18
无法播放音频文件(Can't get audio file to play)

我似乎无法弄清楚为什么我的音频文件无法播放。 音频文件是一个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.

更多推荐

本文发布于:2023-07-04 10:50:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1023509.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:音频文件   无法播放   audio   file   play

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!