将Ogg文件上传到Android中的音频流

时间:2014-04-15 19:04:42

标签: android audio shoutcast icecast

我是网络广播应用程序中的菜鸟。我正在使用icecast这个音频流,所以首先在我的Android应用程序中我捕获了ogg文件中的音频字节,所以我想发送此文件用于音频流。

我的问题我如何发送这个完整的* .ogg文件或其他格式?请帮忙

这是我连接到正在运行的icecast

Socket s = new Socket("101.57.116.17", 8000);
Socket s = new Socket("101.57.116.17", 8000);
Log.d("VS", "Socket Created");
OutputStream out = s.getOutputStream();
Log.d("VS", "Output Stream Established");
PrintWriter output = new PrintWriter(out);
Log.d("VS", "Send Header");
output.println("SOURCE /app ICE/2.3.3");
output.println("content-type: audio/mpeg");
output.println("Authorization: Basic c291cmNlOmhhY2ttZQ==");
output.println("ice-name: Server");
output.println("ice-genre: Rock");
output.println("ice-bitrate: 128");
output.println("ice-private: 0");
output.println("ice-public: 1");
output.println("ice-audio-info: ice-samplerate=44100;ice-bitrate=128;ice-channels=2");
output.println("");
output.flush();
Log.d("VS", "Header sent");
BufferedReader reader = new BufferedReader(new InputStreamReader(
        s.getInputStream()));
String response = reader.readLine();
Log.v(LOG_TAG, response);

HttpClient client = new DefaultHttpClient();

HttpGet httpGET = new HttpGet(
        "http://101.57.116.17:8000/admin/metadata?pass=hackme&mode=updinfo&mount=/app&song=akon");
httpGET.setHeader("Authorization", "Basic c291cmNlOmhhY2ttZQ==");
httpGET.setHeader("User-Agent", "(Mozilla Compatible)");

HttpResponse metaDataResponse = client.execute(httpGET);

System.out.println("Response Code : "
        + metaDataResponse.getStatusLine().getStatusCode());

BufferedReader rd = new BufferedReader(new InputStreamReader(
        metaDataResponse.getEntity().getContent()));

StringBuffer result = new StringBuffer();
String line = "";
while ((line = rd.readLine()) != null) {
    result.append(line);
}

1 个答案:

答案 0 :(得分:1)

连接到Icecast服务器并获得授权后,只需开始沿同一连接发送流数据。

请注意,您需要以播放速度执行此操作。否则,您将超出缓冲区并且客户端的音频要么根本不工作,要么会跳过。