How can I show unity UI Slider filling with unitywebrequest downloadProgress for any file type in an

(Sorry for bad English) Hi, I’m using this code for download assetbundle or .mp4 files via unitywebrequest :

public IEnumerator Download (List<string> urls) {

       for (int i = 0; i < urls.Count; i++) {
          
           string ext = Path.GetExtension (urls[i]);
          
           if (ext == ".mp4") {
                uwr = UnityWebRequest.Get (urls[i]);
           }
           if(ext == ".unity3d") {
                uwr = UnityWebRequestAssetBundle.GetAssetBundle(urls[i]);
           }
          
          
           string fileName = Path.GetFileName (urls[i]);
          
           string path = Path.Combine (myFolder + "/" + fileName);
           uwr.downloadHandler = new DownloadHandlerFile (path);
          
          
           StartCoroutine (ShowDownloadProgress (uwr)); // Progress Bar With Unity Slider
          
           yield return uwr.SendWebRequest ();
          
           if (uwr.isNetworkError || uwr.isHttpError) {
               print ("Error");
           }
           else {
               print ("File successfully downloaded and saved to " + path);
           }          
       }
}

And using this code to show download progress with unity slider:

public IEnumerator ShowDownloadProgress (UnityWebRequest www) {
    while (!www.isDone) {
        downloadProgressSlider.value = www.downloadProgress;
        downloadProgressTxt.text = (string.Format ("{0:0%}", www.downloadProgress));
        yield return new WaitForSeconds (.01f);
    }
    downloadProgressSlider.value = 0;
}

Everything is fine in unity editor when code downloading any file type and I can see the slider value change and fill it:

But my export .apk has a different result, it shows filling slider only when application downloading .mp4 files, but for another file type like .xml,.unity3d or etc. value skip to end for each file!

Any help please?!

UPPPPP!

The progress is only shown when the total download size is known. It’s possible that on Android Content-Length header is not received, hence it’s not possible to generically show the progress.
Try printing out all response headers.

1 Like

@Aurimas-Cernius thanks for the reply,
First: why .mp4 progress work fine?
2th: please write some code for that you say!

Let me google that for you!

https://stackoverflow.com/questions/44855721/unitywebrequest-how-to-print-all-request-headers

1 Like