Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
    Bookmark Topic Watch Topic
  • New Topic

downloading mp3 from stream  RSS feed

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Report post to moderator
can some tell me what im doing wrong here im trying to execute this code using AsyncTask but i can't seem to getting to work. here is the code

class DownloadFilesTask extends AsyncTask<URL, Integer, Long> {
            protected Long doInBackground(URL... urls) {
                try {

                    URLConnection conn = new URL("http://50.7.70.58:8838/live").openConnection();
                    InputStream is = conn.getInputStream();

                    OutputStream outstream = new FileOutputStream(new File("/mnt/sdcard/Download/file.mp3"));
                    byte[] buffer = new byte[4096];
                    int len;
                    while ((len = is.read(buffer)) > 0) {
                        outstream.write(buffer, 0, len);
                    }
                    outstream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }
        }


        new DownloadFilesTask().execute();
 
Saloon Keeper
Posts: 4332
108
  • Mark post as helpful
  • send pies
  • Report post to moderator
What does the code do, and what should it be doing instead? Where does the observed behavior start to deviate from the expected behavior?
 
Sheriff
Posts: 21288
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
Related to https://coderanch.com/t/692675/recording-stream-mp.
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!