FTPサーバーからMP3ファイルをダウンロードしています。これは、MP3ファイルをダウンロードして再生するAndroidアプリケーション用です。ダウンロードは、apache commonsライブラリを使用してJavaで実装され、コードは主に別のチュートリアルに基づいています。ダウンロードは、Javaを実行しているデスクトップで約10mbのファイルをダウンロードするのに非常に高速に動作しますが、Androidデバイスで実行される同じコード(2つ試しました)では、ダウンロードに5〜10分かかると途方もなく遅くなります。同じファイル。(両方のテストはWifi経由で行われました)。
に基づくコード:http ://androiddev.orkitra.com/?p = 28&cpage = 2#comment-40
以下のコードは、使用される2つの方法を示しています。接続とダウンロードです。
public boolean connect(String host, String username, String pass, int port){
try{
mFTPClient.connect(host, port);
if(FTPReply.isPositiveCompletion(mFTPClient.getReplyCode())) {
boolean loginStatus = mFTPClient.login(username, pass);
mFTPClient.setFileType(FTP.BINARY_FILE_TYPE);
mFTPClient.enterLocalPassiveMode();
mFTPClient.setKeepAlive(true);
return loginStatus;
}
} catch (Exception e){
System.err.println("Error: Could not connect to: " + host);
e.printStackTrace();
}
return false;
}
public boolean download(String srcFilePath, String dstFilePath) {
boolean downloadStatus = false;
try {
FileOutputStream dstFileStream = new FileOutputStream(dstFilePath);
downloadStatus = mFTPClient.retrieveFile(srcFilePath, dstFileStream);
dstFileStream.close();
return downloadStatus;
} catch (Exception e) {
System.err.println("Error: Failed to download file from " + srcFilePath + " to " + dstFilePath);
}
return downloadStatus;
}
うまくいけば、私は必要なすべての詳細に言及しました、そして誰かがそれがなぜそんなに遅いのか、そしてもし私がそれを妥当な時間でダウンロードさせることができるとしたらどうしたらいいのか説明できれば幸いです。