MOBILE-2235 h5p: Download in background after play
parent
5903975e8c
commit
3da7c99fd8
|
@ -138,6 +138,13 @@ export class CoreH5PPlayerComponent implements OnInit, OnChanges, OnDestroy {
|
||||||
}).finally(() => {
|
}).finally(() => {
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
this.showPackage = true;
|
this.showPackage = true;
|
||||||
|
|
||||||
|
if (this.canDownload && (this.state == CoreConstants.OUTDATED || this.state == CoreConstants.NOT_DOWNLOADED)) {
|
||||||
|
// Download the package in background if the size is low.
|
||||||
|
this.downloadInBg().catch((error) => {
|
||||||
|
this.logger.error('Error downloading H5P in background', error);
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,6 +176,28 @@ export class CoreH5PPlayerComponent implements OnInit, OnChanges, OnDestroy {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Download the H5P in background if the size is low.
|
||||||
|
*
|
||||||
|
* @return Promise resolved when done.
|
||||||
|
*/
|
||||||
|
protected downloadInBg(): Promise<any> {
|
||||||
|
if (this.urlParams && this.src && this.siteCanDownload && this.h5pProvider.canGetTrustedH5PFileInSite() &&
|
||||||
|
this.appProvider.isOnline()) {
|
||||||
|
|
||||||
|
// Get the file size.
|
||||||
|
return this.pluginFileDelegate.getFileSize({fileurl: this.urlParams.url}, this.siteId).then((size) => {
|
||||||
|
|
||||||
|
if (this.filepoolProvider.shouldDownload(size)) {
|
||||||
|
// Download the file in background.
|
||||||
|
this.filepoolProvider.addToQueueByUrl(this.siteId, this.urlParams.url, this.component, this.componentId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add the resizer script if it hasn't been added already.
|
* Add the resizer script if it hasn't been added already.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -772,7 +772,7 @@ export class CoreFilepoolProvider {
|
||||||
return this.addToQueueByUrl(siteId, fileUrl, component, componentId, timemodified, undefined, undefined,
|
return this.addToQueueByUrl(siteId, fileUrl, component, componentId, timemodified, undefined, undefined,
|
||||||
0, options, revision, true);
|
0, options, revision, true);
|
||||||
}
|
}
|
||||||
} else if (size <= this.DOWNLOAD_THRESHOLD || (isWifi && size <= this.WIFI_DOWNLOAD_THRESHOLD)) {
|
} else if (this.shouldDownload(size)) {
|
||||||
return this.addToQueueByUrl(siteId, fileUrl, component, componentId, timemodified, undefined, undefined, 0,
|
return this.addToQueueByUrl(siteId, fileUrl, component, componentId, timemodified, undefined, undefined, 0,
|
||||||
options, revision, true);
|
options, revision, true);
|
||||||
}
|
}
|
||||||
|
@ -2779,6 +2779,16 @@ export class CoreFilepoolProvider {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a file should be downloaded based on its size.
|
||||||
|
*
|
||||||
|
* @param size File size.
|
||||||
|
* @return Whether file should be downloaded.
|
||||||
|
*/
|
||||||
|
shouldDownload(size: number): boolean {
|
||||||
|
return size <= this.DOWNLOAD_THRESHOLD || (this.appProvider.isWifi() && size <= this.WIFI_DOWNLOAD_THRESHOLD);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience function to check if a file should be downloaded before opening it.
|
* Convenience function to check if a file should be downloaded before opening it.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue