inputstream - Android record stream can't stop -
i want record streaming radio
now code
press.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { string filename = environment.getexternalstoragedirectory().getabsolutepath(); filename += "/music.mp3"; outputsource= new file(filename); bytesread = -1; url url; try { url = new url("** url **"); inputstream = url.openstream(); log.d(log_tag, "url.openstream()"); fileoutputstream = new fileoutputstream(outputsource); log.d(log_tag, "fileoutputstream: " + outputsource); while ((c = inputstream.read()) != -1) { fileoutputstream.write(c); bytesread++; } } catch (malformedurlexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } } });
when click button run continuously , can't stopped, when click stop button said me program not responding have wait or exit
so how can start record when click record button , stop when click stop button ?
you network operations on ui thread. not wrong, throw networkonmainthreadexception
use asynctask or create new thread, terminated on cancel.
Comments
Post a Comment