0

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);
}
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Rolanddev
  • 49
  • 7
  • 1
    Since you're downloading the file by its download URL, reporting progress has nothing to do with Firebase Storage anymore. You might want to search for a [android downloadmanager progress bar example](https://www.google.com/search?q=android+downloadmanager+progress+bar+example). – Frank van Puffelen Mar 28 '20 at 14:48
  • thank you very much, it was indeed my concern ..I put myself there – Rolanddev Mar 28 '20 at 15:37

0 Answers0