diff --git a/lib/net/http_fetch_plugin.js b/lib/net/http_fetch_plugin.js index 249fdfdcab..9637d16fbb 100644 --- a/lib/net/http_fetch_plugin.js +++ b/lib/net/http_fetch_plugin.js @@ -167,8 +167,10 @@ shaka.net.HttpFetchPlugin = class { // is long enough, or if a whole segment is downloaded, call // progressUpdated(). if (currentTime - lastTime > 100 || readObj.done) { + const numBytesRemaining = + readObj.done ? 0 : contentLength - loaded; progressUpdated(currentTime - lastTime, loaded - lastLoaded, - contentLength - loaded); + numBytesRemaining); lastLoaded = loaded; lastTime = currentTime; } diff --git a/lib/net/http_xhr_plugin.js b/lib/net/http_xhr_plugin.js index aec4ec6de2..37f9db0670 100644 --- a/lib/net/http_xhr_plugin.js +++ b/lib/net/http_xhr_plugin.js @@ -67,6 +67,9 @@ shaka.net.HttpXHRPlugin = class { const xhrResponse = xhr.response; try { + const currentTime = Date.now(); + progressUpdated(currentTime - lastTime, event.loaded - lastLoaded, + /* numBytesRemaining= */ 0); const response = shaka.net.HttpPluginUtils.makeResponse(headers, xhrResponse, xhr.status, uri, xhr.responseURL, requestType); resolve(response); @@ -97,8 +100,10 @@ shaka.net.HttpXHRPlugin = class { // progressUpdated(). if (currentTime - lastTime > 100 || (event.lengthComputable && event.loaded == event.total)) { + const numBytesRemaining = + xhr.readyState == 4 ? 0 : event.total - event.loaded; progressUpdated(currentTime - lastTime, event.loaded - lastLoaded, - event.total - event.loaded); + numBytesRemaining); lastLoaded = event.loaded; lastTime = currentTime; }