2011-07-13 7 views
1

フォーラムを検索する前に既にフォーラムを検索しています(私はこの問題を解決していないので、この投稿を作成しています)。 私はshoutcastサーバーからオーディオストリームを再生するJavaアプリケーションを作成したいと思います。私はウェブを見て、javazoomが私がやりたいことに役立つことがわかった。だから私は彼らのパッケージをダウンロードし、実験を開始しました。 私はこれを作ってみたが、私は「javax.sound.sampled.UnsupportedAudioFileExceptionを:入力されたURLからオーディオ入力ストリームを取得できませんでし」を取得:あなたはjava + shoutcast stream

/* 
* To change this template, choose Tools | Templates 
* and open the template in the editor. 
*/ 
package test; 

/** 
* 
* @author George 
*/ 


import java.io.*; 
import java.util.Map; 
import java.net.*; 
import javax.sound.sampled.*; 

public class play { 
    public void testPlay(String filename) 
{ 
    try { 

    // File file = new File(filename); 
     URL file= new URL(filename); 
    AudioInputStream in= AudioSystem.getAudioInputStream(file); 
    AudioInputStream din = null; 
    AudioFormat baseFormat = in.getFormat(); 
    AudioFormat decodedFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 
                        baseFormat.getSampleRate(), 
                        16, 
                        baseFormat.getChannels(), 
                        baseFormat.getChannels() * 2, 
                        baseFormat.getSampleRate(), 
                        false); 
    din = AudioSystem.getAudioInputStream(decodedFormat, in); 
    // Play now. 
    rawplay(decodedFormat, din); 
    in.close(); 


    din = AudioSystem.getAudioInputStream(decodedFormat, in); 
// DecodedMpegAudioInputStream properties 
if (din instanceof javazoom.spi.PropertiesContainer) 
{ 
    Map properties = ((javazoom.spi.PropertiesContainer) din).properties(); 
    float[] equalizer = (float[]) properties.get("mp3.equalizer"); 
    equalizer[0] = (float) 0.5; 
    equalizer[31] = (float) 0.25; 
} 




    } catch (Exception e) 
    { 
     System.out.println(e); 
    } 
} 

private void rawplay(AudioFormat targetFormat, AudioInputStream din) throws IOException,                        LineUnavailableException 
{ 
    byte[] data = new byte[4096]; 
    SourceDataLine line = getLine(targetFormat); 
    if (line != null) 
    { 
    // Start 
    line.start(); 
    int nBytesRead = 0, nBytesWritten = 0; 
    while (nBytesRead != -1) 
    { 
     nBytesRead = din.read(data, 0, data.length); 
     if (nBytesRead != -1) nBytesWritten = line.write(data, 0, nBytesRead); 
    } 
    // Stop 
    line.drain(); 
    line.stop(); 
    line.close(); 
    din.close(); 
    } 
} 

private SourceDataLine getLine(AudioFormat audioFormat) throws LineUnavailableException 
{ 
    SourceDataLine res = null; 
    DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat); 
    res = (SourceDataLine) AudioSystem.getLine(info); 
    res.open(audioFormat); 
    return res; 
} 
} 
+0

明らかに、指定されたタイプのオーディオストリームをサポートするlibsがありません。 mp3か何でもかまいません –

答えて

1

です。ここ

コードですあなたが持っているURLがMP3データ用のものであることを確かめてください。あなたはストリームからローカルにいくつかのデータを保存し、それをMP3ファイルとして標準のメディアプレーヤーアプリから再生できるはずです。そうでない場合は、おそらくストリームが不良であるか、他のフォーマットのストリームがあります。

また、MP3サポートを得るためにJavaZoomが提供するオーディオライブラリの実装を使用していますか? Javaはデフォルトでそれを持っていません。

また、shoutcastストリームからHTTP応答ヘッダーを読み取ろうとすると、配信されるコンテンツに関する詳細情報が表示されることがあります。

幸運。

関連する問題