0

そのようなソケットを使用して、手動で HTTP ライブストリームに接続できます。

Socket radio = new Socket();
radio.connect(new InetSocketAddress("streaming.fueralle.org", 8000));
PrintWriter out = new PrintWriter(radio.getOutputStream());
out.println("GET /corax.mp3 HTTP/1.0");
out.println("User-Agent: Wget/1.8.2");
out.println("Host: streaming.fueralle.org:8000");
out.println("Accept: */*");
out.println("Connection: Keep-Alive");
out.println("");
out.flush();

DataInputStream is = new DataInputStream(radio.getInputStream());
String headerLine = is.readLine();
while(headerLine.length() > 0){
    resp.getWriter().println("next line is " + headerLine);
    headerLine = is.readLine();
}

ここで、代わりに URL と HttpUrlConnection を使用してこの接続を行う必要があります (ソケットを許可しない Google App Engine から実行する予定です)。しかし、私は重要な部分を見逃しているようです。heise.de のような静的ページを試してみると、うまくいきます。しかし、連続ストリームの読み取りを開始できません。

EDIT2: ソース (およびプロジェクト全体) を github に置きました。https://github.com/flaschenpost/GoogleAppRadio/blob/master/MGRadio/src/de/gergele/mgradio/MGRadioServlet.java

ここにスニペットがあります。

URL u = new URL("http://streaming.fueralle.org:8000/corax.mp3");
// URL u = new URL("http://www.heise.de");
System.out.println("trying to connect!" + u);
HttpURLConnection conn = (HttpURLConnection)u.openConnection();
conn.addRequestProperty("User-Agent", "MGet/1.0.0");
conn.addRequestProperty("Accept", "*/*");
// conn.addRequestProperty("Connection", "Keep-Alive");
// EDIT: I tried with and without setChunkedStreamingMode, I hoped it would 
//       tell the connection-object about the streaming mode from the server
conn.setChunkedStreamingMode(4096);
System.out.println("setup finished..." + conn + " " + conn.getRequestProperties().toString());
System.out.println(" type: " + conn.getContentType());

DataInputStream is = new DataInputStream(conn.getInputStream());

ただし、ヘッダーから 1 文字を読み取る前に TimeoutException が発生します。

それでは、私の質問: HTTP 接続をソケット接続と同じくらいうまく調整するにはどうすればよいですか? 本当に独自の URLStreamHandlerFactory を作成する必要がありますか? 少し奇妙に聞こえます...

wget と curl はそのストリームを簡単に取得します。私はすでに半夜を費やして、Java URL がこれらのライブストリームに対して何らかの形で多くの魔法を含んでいるように見えることを発見しました。

助けてくれてありがとう!

4

1 に答える 1

0

ライブ ストリーミングに Google アプリ エンジンを使用することはできません。GAE フレームワークには、サーブレットの実行時間の証明に時間制限があります。バックグラウンド タスク (gae のバックエンド) を使用する場合は、料金を支払う必要があります。それでも、ストリームを保存することしかできず、ライブでストリーミングすることはできません.

于 2013-10-31T20:46:11.223 に答える