Download MP3 file from server in sd card in Android -
i want download mp3 files server 1 one , save sd card folder. have no errors or exception mp3 not downloaded , not show in sd card. can how solve issue.here code.
if (imagename.endswith(mp3_pattern)) { str_downloadurl = namespace + "/downloadfile/filename/" + imagename; log.e("######### ", "str_downloadurl = " + str_downloadurl); download_mp3file(str_downloadurl); strdownloadstatus = "1"; dbhelper.update_downloadstatus(imagename, strdownloadstatus); } void download_mp3file(final string fileurl) { new asynctask<string, integer, string>() { @override protected string doinbackground(string... arg0) { int count; file file = new file(newfolder, system.currenttimemillis() + imagename); try { url url = new url(fileurl); urlconnection conexion = url.openconnection(); conexion.connect(); // useful can show tipical 0-100% progress bar int lenghtoffile = conexion.getcontentlength(); // downlod file inputstream input = new bufferedinputstream(url.openstream()); outputstream output = new fileoutputstream(file); byte data[] = new byte[1024]; long total = 0; while ((count = input.read(data)) != -1) { total += count; // publishing progress.... publishprogress((int) (total * 100 / lenghtoffile)); output.write(data, 0, count); } output.flush(); output.close(); input.close(); } catch (exception e) { } return null; } }.execute(); }
place breakpoint in inputstream object see there stream. debug output stream see results.
Comments
Post a Comment