ビデオファイルをループ再生するアプリケーションを開発中です。これまでは、デバイスをマウントしてビデオ ファイルを SD カードにコピーし、ファイル パスを使用して VideoView で起動していました。再生するビデオをリモートで更新できる方法を実装しようとしているので、ビデオをオンラインで保存することにしました。アプリ内でローカル コピーをチェックし、存在しない場合、または新しいコピーがある場合はダウンロードします。両方とも .mp4 の 2 つの異なるビデオ ファイルでテストしました。それらの1つをダウンロードした後、初めて再生しますが、ループを再度開始しようとすると、ビデオを再生できないと表示されます。もう一方は初めて再生することさえできず、ビデオを再生できないというダイアログが表示されるだけです。これらのファイルは両方とも、USB ケーブル経由で SD カードにコピーすると、アプリで正しく動作します。アプリを終了し、他の何か(ドロップボックス)で手動でダウンロードすると機能しますが、アプリ内からダウンロードすると機能しません。ファイルをダウンロードするために使用しているコードは次のとおりです。
public static void DownloadFromUrl(String fileName) { //this is the downloader method
try {
URL url = new URL("http://dl.dropbox.com/u/myfile.mp4");
File file = new File(PATH + fileName);
long startTime = System.currentTimeMillis();
Log.d(myTag, "download begining");
Log.d(myTag, "download url:" + url);
Log.d(myTag, "downloaded file name:" + fileName);
/* Open a connection to that URL. */
URLConnection ucon = url.openConnection();
Log.i(myTag, "Opened Connection");
/*
* Define InputStreams to read from the URLConnection.
*/
InputStream is = ucon.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
Log.i(myTag, "Got InputStream and BufferedInputStream");
FileOutputStream fos = new FileOutputStream(file);
BufferedOutputStream bos = new BufferedOutputStream(fos);
Log.i(myTag, "Got FileOutputStream and BufferedOutputStream");
/*
* Read bytes to the Buffer until there is nothing more to read(-1).
*/
int current = 0;
Log.i(myTag, "About to write");
while ((current = bis.read()) != -1) {
bos.write(current);
}
fos.close();
Log.d(myTag, "download ready in"
+ ((System.currentTimeMillis() - startTime))
+ " sec");
} catch (IOException e) {
Log.d(myTag, "Error: " + e);
}
}
I know the dropbox url in this snippet is not correct I changed it only for this post, in my app the url is pointing to a file correctly. And the variable PATH thats used when creating the File is set in my code outside of this snippet.
Is there something about this code snippet that could be corrupting my mp4 files?