【问题标题】:Is there a way to make JavaSound to use the codecs installed on your SO?有没有办法让 JavaSound 使用安装在你的 SO 上的编解码器?
【发布时间】:2010-06-27 13:36:41
【问题描述】:

我正在使用带有以下代码的 java Sound:

public static void main(String[] args) throws Exception
{
    JFrame frame = new JFrame();
    frame.setSize(200,200);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
    JFileChooser fc = new JFileChooser();
    fc.showOpenDialog(null);
    File f = fc.getSelectedFile();
    AudioInputStream ais = AudioSystem.getAudioInputStream(f);
    AudioFormat format = ais.getFormat();
    AudioFormat decodedFormat = new AudioFormat(
                AudioFormat.Encoding.PCM_SIGNED,  // Encoding to use
                    format.getSampleRate(),           // sample rate (same as base format)
                    16,               // sample size in bits (thx to Javazoom)
                    format.getChannels(),             // # of Channels
                    format.getChannels()*2,           // Frame Size
                    format.getSampleRate(),           // Frame Rate
                    false                 // Big Endian
            );
    SourceDataLine line = AudioSystem.getSourceDataLine(decodedFormat);
    AudioInputStream dais = AudioSystem.getAudioInputStream(decodedFormat, ais);
    line.open(decodedFormat);
    line.start();
    byte[] b = new byte[1024];
    int i=0;
    while(true)
    {
        i = dais.read(b, 0, b.length);
        if(i == -1)
            break;
        line.write(b, 0, i);
    }
    line.drain();
    line.stop();
    line.close();
    ais.close();
    dais.close();


}

但是要播放 mp3,tihs 要求我的类路径上有一个 SPI……没关系,尽管我一直在寻找一种方法来使用安装在 SO 中的编解码器。 有没有办法做到这一点?

【问题讨论】:

    标签: java audio mp3 codec javasound


    【解决方案1】:

    【讨论】:

    • 我明白了...但是您没有使用 SO 的编解码器。您像我一样在类路径中使用 SPI。我试图让它与已经安装的 SO 编解码器一起工作
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-09
    • 2014-01-15
    • 1970-01-01
    • 1970-01-01
    • 2022-11-11
    • 1970-01-01
    • 2013-10-24
    相关资源
    最近更新 更多