无法播放音频文件 [英] Can't get audio file to play

查看:127
本文介绍了无法播放音频文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法弄清楚为什么我的音频文件无法播放.音频文件是WAV文件,只是.我得到的错误是javax.sound.sampled.UnsupportedAudioFileException.

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文件的属性,并了解其是否匹配.

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.

DAW产生具有24位或32位编码或48000fps或92000fps的wav文件的情况越来越普遍.

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.

可以使用Audacity之类的工具将其转换为"CD"编码规范.

It is possible to convert these to the "CD" encoding spec with a tool such as Audacity.

这篇关于无法播放音频文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆