thieumao

Download mp3 with Android

Apr 21st, 2014
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1.         // try{
  2.         try {
  3.             File cacheDir = new File(
  4.                     android.os.Environment.getExternalStorageDirectory(),
  5.                     "Folder Name");
  6.             if (!cacheDir.exists())
  7.                 cacheDir.mkdirs();
  8.  
  9.             File f = new File(cacheDir, "songname" + ".mp3");
  10.             URL url = new URL(
  11.                     "http://210.211.99.70/teenpro.vn/files/song/zg/zg_Co-Khi-Nao-Roi-Xa-Bich-Phuong.mp3");
  12.  
  13.             InputStream input = new BufferedInputStream(url.openStream());
  14.             OutputStream output = new FileOutputStream(f);
  15.  
  16.             byte data[] = new byte[1024];
  17.             long total = 0;
  18.             int count = 0;
  19.             while ((count = input.read(data)) != -1) {
  20.                 total++;
  21.                 Log.e("while", "A" + total);
  22.                 output.write(data, 0, count);
  23.             }
  24.  
  25.             output.flush();
  26.             output.close();
  27.             input.close();
  28.         } catch (Exception e) {
  29.             e.printStackTrace();
  30.         }
Add Comment
Please, Sign In to add comment