I am using the following code for downloading the video from the internet:
class DownloadFile1 extends AsyncTask<String, Integer, String> {
public String videoToDownload;
public String fileName;
@Override
protected String doInBackground(String... params) {
int count;
try {
mp4load(videoToDownload);
} catch (Exception e) {
// TODO: handle exception
}
return null;
}
public void mp4load(String urling) {
try {
System.out.println("Downloading");
URL url = new URL(urling);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
//c.setDoOutput(true);
con.connect();
// String downloadsPath = Environment.getExternalStoragePublicDirectory();
File SDCardRoot = Environment.getExternalStorageDirectory();
File outputFile = new File(SDCardRoot, fileName);
if (!outputFile.exists()) {
outputFile.createNewFile();
}
FileOutputStream fos = new FileOutputStream(outputFile);
int status = con.getResponseCode();
InputStream is = con.getInputStream();
byte[] buffer = new byte[1024];
int len1 = 0;
while ((len1 = is.read(buffer)) != -1) {
fos.write(buffer, 0, len1);
}
fos.close();
is.close();
System.out.println("Downloaded");
} catch (IOException e) {
e.printStackTrace();
}
}
I want to add progress bar until the video gets downloaded.The progress bar should be displayed from the start of the download to the end of the download in any format (i.e) it can be a circular progress bar etc.How to do this?
I have a code to add progress bar in async task.Whether the following code is correct?
@Override
protected void onPostExecute(Void result) {
bar.dismiss();
super.onPostExecute(result);
}
@Override
protected void onPreExecute() {
bar = new ProgressDialog(activity);
bar.setMessage("Processing...");
bar.setIndeterminate(true);
super.onPreExecute();
}