I understand that sending a stream is done in the following way - Open the socket. Send the data. Sign in. Send the meta data. Send the audio stream to the same socket.

Here is the code

Socket s = new Socket("141.4.209.112", 8088); 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("icy-name: Server"); output.println("icy-genre: Rock"); output.println("icy-bitrate: 128"); output.println("icy-private: 0"); output.println("icy-public: 1"); output.println("icy-audio-info: icy-samplerate=44100;icy-bitrate=128;icy- 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://141.4.209.112:8088/admin.cgi?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); } 

Completely executed, updates the song data (adds a new one), but it’s not clear how to send the stream.

But this code

 s = new Socket(SP_url, 8088); s.setSoTimeout(5000); System.out.println("Streaming -> Socket open"); OutputStream os = s.getOutputStream(); System.out.println("Streaming -> Get output"); String user_agent = "WinampMPEG/5.09"; String req="GET / HTTP/1.1\r\nHost: "+SP_url+"/\r\nuser-agent: "+user_agent+"\r\nIcy-MetaData: 1\r\nConnection: keep-alive\r\n\r\n"; os.write(req.getBytes()); System.out.println("Streaming -> Send GET"); InputStream is = s.getInputStream(); System.out.println("Streaming -> Get Input"); BufferedReader br = new BufferedReader(new InputStreamReader(is)); int bitrate = 0; String line = br.readLine(); String lines = ""; while(line != null && !line.isEmpty()){ lines = lines + line; if(line.contains("icy-br")) { try{ bitrate = Integer.parseInt(line.split(":")[1].trim()); }catch(Exception ex) { System.out.println("Streaming -> Error parsing bitrate"); } } System.out.println("["+line+"]"); line = br.readLine(); } //---------------------------------------UPDATE SONG HttpClient client = new DefaultHttpClient(); System.out.println("Streaming -> Create GET request"); HttpGet httpGET = new HttpGet( "http://"+SP_url+":8088/admin.cgi?" + "pass="+SP_pass+"&" + "mode=updinfo&url=http://"+SP_url+":8088/&song=O111"); httpGET.setHeader("Authorization", "Basic c291cmNlOmhhY2ttZQ=="); httpGET.setHeader("User-Agent", "(Mozilla Compatible)"); HttpResponse metaDataResponse = client.execute(httpGET); System.out.println("Streaming -> Send UPDATE Song"); System.out.println("Response Code : " + metaDataResponse.getStatusLine().getStatusCode()); //--------------------------------------- System.out.println("Open Socket"); os.write("gf677nvc\r\n".getBytes()); os.write("icy-name:name1\r\n".getBytes()); os.write("icy-genre:genre1\r\n".getBytes()); os.write("icy-pub:0\r\n".getBytes()); os.write("icy-br:128000\r\n".getBytes()); os.write("icy-url:http://ricco.com\r\n".getBytes()); os.write("icy-irc:NONE1\r\n".getBytes()); os.write("icy-icq:NONE1\r\n".getBytes()); os.write("icy-aim:NONE1\r\n".getBytes()); os.write("content-type:audio/aacp\r\n".getBytes()); os.write("icy-reset:1\r\n".getBytes()); os.write("\r\n".getBytes()); input = s.getInputStream(); //--------------------------------------- System.out.println("Streaming -> END"); 

I get a server response from the socket - 401 on port 8088 and 402 on port 8089 and 200OK on port 8000. But there is nothing on port 8000. Winamp connects to port 8088 without problems.

Can someone tell me how to do this? send stream from microphone to server?

    1 answer 1

    Everything worked - it turned out you need to specify the correct HTTP header

    Found on the site Mozilla

     String req="GET / HTTP/1.0\r\n" + "User-Agent:Mozilla/5.0 (Android; Mobile; rv:40.0) Gecko/40.0 Firefox/40.0\r\n" + "icy-metadata:1\r\n" + "Connection: keep-alive\r\n\r\n"; os.write(req.getBytes()); 

    began to receive a response 200OK