android 获取mp3专辑id,android-如何通过使用音频文件ID获取soundclou...

我自己修复它,我使用的是android,流URL也是下载URL.流URL也是要下载的下载URL,但不会影响下载次数.你可以这样尝试

String file_url = "https://api.soundcloud.com/tracks/93216523/stream?client_id=4346c8125f4f5c40ad666bacd8e96498";

将此网址传递给asyntack并管理您的下载,您可以像这样传递它

new DownloadFileFromURL().execute(file_url);

这是使用asyntask的DownloadFileFromUR类

class DownloadFileFromURL extends AsyncTask {

@Override

protected void onPreExecute() {

super.onPreExecute();

}

@Override

protected String doInBackground(String... f_url) {

URL u = null;

InputStream is = null;

try {

u = new URL(f_url[0]);

is = u.openStream();

HttpURLConnection huc = (HttpURLConnection)u.openConnection();//to know the size of video

int size = huc.getContentLength();

if(huc != null){

String fileName = "FILE2.mp3";

String storagePath = Environment.getExternalStorageDirectory().toString();

File f = new File(storagePath,fileName);

FileOutputStream fos = new FileOutputStream(f);

byte[] buffer = new byte[1024];

long total = 0;

int len1 = 0;

if(is != null){

while ((len1 = is.read(buffer)) > 0) {

total+=len1;

publishProgress((int)((total*100)/size));

fos.write(buffer,0, len1);

}

}

if(fos != null){

fos.close();

}

}

}catch (MalformedURLException mue) {

mue.printStackTrace();

} catch (IOException ioe) {

ioe.printStackTrace();

} finally {

try {

if(is != null){

is.close();

}

}catch (IOException ioe) {

// just going to ignore this one

}

}

return "";

}

@Override

protected void onPostExecute(String file_url) {

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值