using java to record mp3

I want to stream music from url and record it but for some reason i keep getting an err when i use this line InputStream is = conn.getInputStream(); here is by code. why is not working?

URLConnection conn = null;


conn = new URL("http://50.7.70.58:8708").openConnection;

InputStream is = conn.getInputStream();
BufferedInputStream in = new BufferedInputStream(is);

OutputStream out = new BufferedOutputStream(new FileOutputStream(new File("/mnt/sdcard/Download/output.mp3")));
byte[] buf = new byte[256];
int n = 0;
while ((n=in.read(buf))>=0) {
out.write(buf, 0, n);
}
out.flush();
out.close();
What error do you get ?
Next time, please post the exact error message as Thomas1965 said. We aren't psychic, in the general case :)

However, your issue seems to be pretty simple. openConnection is a function, add a set of parentheses to it.

conn = new URL("http://50.7.70.58:8708").openConnection();
I had deleted that by mistake when i put the code up, but it does not work? it keeps crashing when i run it
Last edited on
here is the err im getting

04-09 17:18:11.921 377-455/system_process I/qtaguid: Failed write_ctrl(s 0 10055) res=-1 errno=1
04-09 17:18:11.921 377-455/system_process W/NetworkManagementSocketTagger: setKernelCountSet(10055, 0) failed with errno -1
If all you're doing is copying a stream from an internet endpoint to a file, why not use netcat?

req.txt
GET / HTTP/1.1
Host: 50.7.70.58
User-Agent: netcat



nc 50.7.70.58 8708 < req.txt > out.txt
Actually the url is just an html file. When you click on the link for the stream you get redirected where you need to login - after you have paid and registered.
I get a stream with netcat.

It might be better to write to an mp3 file.
 
nc 50.7.70.58 8708 < req.txt > out.mp3

Last edited on
Topic archived. No new replies allowed.