I'm trying to set up a voicemail much like that of WhatsApp so that the user clicks on the "play" button; the app first downloads the file before allowing it to play. The download works but I don't know how to integrate the progress bar.
public void Download(){
int mtn = i++ ;
final StorageReference ref2 = storageReference.child("/Audio/").child("new_audio0.mp3");
ref2.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
DownLoadFile(context,"new_audio",".mp3",DIRECTORY_DOWNLOADS, uri);
Log.i("URL_LINK", uri.toString());
Toast.makeText(context, "En cours de télechargement..", Toast.LENGTH_SHORT).show();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(context, "Le telechargement a échoué", Toast.LENGTH_SHORT).show();
}
}).addOnCompleteListener(new OnCompleteListener<Uri>() {
@Override
public void onComplete(@NonNull Task<Uri> task) {
}
});
}
public void DownLoadFile(Context context , String fileName , String fileExtension, String DestinationDirectory, Uri uri ){
DownloadManager downloadManager = (DownloadManager)context.getSystemService(Context.DOWNLOAD_SERVICE);
DownloadManager.Request request = new DownloadManager.Request(uri);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalFilesDir(context,DestinationDirectory, fileName + fileExtension);
assert downloadManager != null;
downloadManager.enqueue(request);
}