[英]Could'nt download file on Android while on PC it downloads ok (amazon)
Got an weird issue. 有一个奇怪的问题。 A file with Url: https://s3.amazonaws.com/myappdata/msg/171401089927.mp3 (not available any more) downloads ok on PC and its mp3 file.
网址为https://s3.amazonaws.com/myappdata/msg/171401089927.mp3的文件(不再可用)可以在PC及其mp3文件上正常下载。 But when I try to DL it on Android FOA Im getting content-type "application/xml" instead of "audio/mpeg" and when downloading starts I'm getting:
但是,当我尝试在Android FOA上对其进行DL下载时,我得到的是内容类型“ application / xml”而不是“ audio / mpeg”,并且在开始下载时,我得到了:
05-30 12:13:44.478: E/PlayerService(28023): java.io.FileNotFoundException: https://s3.amazonaws.com/myappdata/msg/171401089927.mp3
05-30 12:13:44.478: E/PlayerService(28023): at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:177)
05-30 12:13:44.478: E/PlayerService(28023): at libcore.net.http.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:270)
The code used to DL: 用于DL的代码:
/**
* Download the url stream to a temporary location
*/
public void downloadAudioIncrement(String mediaUrl) throws IOException {
Log.i(TAG, "downloadAudioIncrement(): mediaUrl: "+mediaUrl+"\ncacheDir: "+cacheDir);
URL url = null;
try {
url = new URL(mediaUrl);
} catch (MalformedURLException e) {
e.printStackTrace();
throw new IOException("Unable to create InputStream for mediaUrl:" + mediaUrl);
}
// this file will represent whole downloaded song
mp3FileDownloaded = new File(cacheDir, mp3FileName);
if (!mp3FileDownloaded.exists())
//FileUtils.makeDirsForFile(mp3FileDownloaded);
try{
mp3FileDownloaded.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
if (!mp3FileDownloaded.canWrite())
throw new IOException("Can't open temporary file for writing");
HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();
urlConnection.setReadTimeout(1000 * 20);
urlConnection.setConnectTimeout(1000 * 5);
urlConnection.setDoInput(true);
urlConnection.setDoOutput(true);
int mp3BytesSize = urlConnection.getContentLength();
// final String
// contentLengthStr=urlConnection.getHeaderField("content-length");
String ctype = urlConnection.getContentType();
if (ctype == null) {
ctype = "";
} else {
ctype = ctype.toLowerCase(Locale.US);
}
// See if we can handle this type
Log.i(TAG, "Content Type: " + ctype);
if ( ctype.contains("audio/mpeg") || TextUtils.isEmpty(ctype) ) {
String temp = urlConnection.getHeaderField(BITRATE_HEADER);
Log.i(TAG, "Bitrate: " + temp);
// if (temp != null){
// bitrate = new Integer(temp).intValue();
// }
} else {
Log.e(TAG, UNSUPPORTED_AUDIO_TYPE+": " + ctype);
// throw new IOException(UNSUPPORTED_AUDIO_TYPE+": " + ctype);
// Log.e(TAG, "Or we could not connect to audio");
// stop();
// return;
}
final InputStream stream = new BufferedInputStream(urlConnection.getInputStream(),8192);
...
Right at the last shown line of code (instantiating the InputStream stream) the mentioned IOExeption raised. 在最后显示的代码行(实例化InputStream流)的右边,提到了IOExeption。 There are other mp3 files exists at same location and they are downloading with no any issue but only mentioned above url fails.
在相同位置还存在其他mp3文件,它们正在下载,没有任何问题,但仅上述url失败。
What could be wrong here? 这有什么问题吗?
UPDATE UPDATE
Its appears that this issue happens on HTC Rezound with AOS 4.0.4. 看来此问题发生在带有AOS 4.0.4的HTC Rezound上。 On other device, with AOS 2.3.5 everything works ok.
在其他设备上,使用AOS 2.3.5,一切正常。
seems like the line 似乎像线
urlConnection.setDoOutput(true);
was the source of issue since I don't upload any data. 是问题的根源,因为我没有上传任何数据。 Everything works fine since I'd comment it.
一切正常,因为我会发表评论。 Also these FileNotFoundException while getting the InputStream object from HttpURLConnection and Android HttpUrlConnection getInputStream throws NullPointerException threads might be helpfull.
同样,在从HttpURLConnection和Android HttpUrlConnection 获取InputStream对象时,这些FileNotFoundException 抛出NullPointerException线程可能也会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.