gpt4 book ai didi

java - 有没有办法让JavaSound使用您SO上安装的编解码器?

转载 作者:行者123 更新时间:2023-12-03 02:27:27 25 4
gpt4 key购买 nike

我正在将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,这需要我在类路径上有一个SPI ...好的,尽管如此,我一直在寻找一种使用SO中安装的编解码器的方法。
有没有办法做到这一点?

最佳答案

I have used this to play MP3s,这很简单。

关于java - 有没有办法让JavaSound使用您SO上安装的编解码器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3127500/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com