2010-06-27 74 views
0

我使用Java聲音用下面的代碼:有沒有辦法讓JavaSound使用你的SO上安裝的編解碼器?

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對我的類路徑...它的確定,altough我一直在尋找一種方式來使用編解碼器安裝在SO中。 有沒有辦法做到這一點?

回答

0
+0

我明白了......但您並未使用SO的編解碼器。你像我一樣在你的類路徑中使用SPI。 我試圖使它與已經安裝的SO編解碼器一起工作 – fredcrs 2010-08-13 11:41:01

相關問題