[英]Downloaded song is not playing from sdcard?
我可以在SD卡中從Sound Cloud下載聲音文件。 我可以將其設置為我的鈴聲,並且可以正常使用。 但是,當我嘗試從SD卡播放音樂時,出現了“文件不受支持”消息,並且音樂無法播放。 我想我沒有得到文件擴展名,這就是為什么音樂無法播放的原因。請幫助我。
case PARSE_GET_TRACK:
...
case PARSE_DOWNLOAD_TRACK:
String fileName = mTrack.getTrackTitle()
+ mTrack.getTrackId();
String path = mTrack.getDownloadUrl()
+"?client_id=xxx";
URL u = new URL(path);
httpRequest = new HttpGet(u.toURI());
httpclient = new DefaultHttpClient();
response = (HttpResponse) httpclient.execute(httpRequest);
HttpURLConnection c = (HttpURLConnection) u
.openConnection();
c.setRequestMethod("GET");
c.setDoInput(true);
c.setDoOutput(true);
c.connect();
File sdCard = Environment.getExternalStorageDirectory();
File dir = new File(sdCard.getAbsolutePath() + "/dir1/dir2");
dir.mkdirs();
File file = new File(dir, fileName);
mTrack.setAboluteFilePath(file.getAbsolutePath());
boolean redirect = false;
int status = c.getResponseCode();
if (status != HttpURLConnection.HTTP_OK) {
if (status == HttpURLConnection.HTTP_MOVED_TEMP
|| status == HttpURLConnection.HTTP_MOVED_PERM
|| status == HttpURLConnection.HTTP_SEE_OTHER)
redirect = true;
}
if (redirect) {
String newUrl = c.getHeaderField("Location");
c = (HttpURLConnection) new URL(newUrl)
.openConnection();
}
InputStream inputStream = response.getEntity().getContent();
InputStreamReader inputStreamReader = new InputStreamReader(
inputStream);
BufferedReader bufferedReader = new BufferedReader(
inputStreamReader);
BufferedInputStream bis = new BufferedInputStream(
inputStream, 1024 * 50);
FileOutputStream fos = new FileOutputStream(file);
byte[] buffer = new byte[1024 * 50];
int current = 0;
while ((current = bis.read(buffer)) != -1) {
fos.write(buffer, 0, current);
}
fos.flush();
StringBuilder stringBuilder = new StringBuilder();
String bufferedStrChunk = null;
while ((bufferedStrChunk = bufferedReader.readLine()) != null) {
stringBuilder.append(bufferedStrChunk);
}
fos.close();
bis.close();
return stringBuilder.toString();
case PARSE_GET_VID_THUMB:
....
是的,在嘗試了一些其他方法之后,我解決了它。 您只需要更改Track ID的字符串即可。
String fileName = mTrack.getTrackTitle()
+ mTrack.getTrackId()+ ".3gp";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.