Skip to content

Commit fb8f3a8

Browse files
authored
Merge pull request #4288 from dpalou/MOBILE-4738
MOBILE-4738 h5pactivity: Use online player if download file fails
2 parents 7ed6583 + 26dc108 commit fb8f3a8

File tree

2 files changed

+26
-33
lines changed

2 files changed

+26
-33
lines changed

src/addons/mod/h5pactivity/components/index/addon-mod-h5pactivity-index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@
5959
</ion-item>
6060

6161
<!-- Button to download the package. -->
62-
<ion-button *ngIf="!downloading && needsDownload" class="ion-text-wrap ion-margin" expand="block" (click)="downloadAndPlay($event)">
62+
<ion-button *ngIf="!downloading && needsDownload" class="ion-text-wrap ion-margin" expand="block"
63+
(click)="downloadAndPlayManually($event)">
6364
{{ 'addon.mod_h5pactivity.downloadh5pfile' | translate }}
6465
</ion-button>
6566

src/addons/mod/h5pactivity/components/index/index.ts

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv
226226
this.deployedFile?.filesize &&
227227
CoreFilepool.shouldDownload(this.deployedFile.filesize)
228228
) {
229-
// Package is small, download it automatically. Don't block this function for this.
230-
this.downloadAutomatically();
229+
// Package is small, download and play it automatically. Don't block this function for this.
230+
this.downloadAndPlay();
231231
}
232232
}
233233

@@ -388,9 +388,8 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv
388388
* Download the file and play it.
389389
*
390390
* @param event Click event.
391-
* @returns Promise resolved when done.
392391
*/
393-
async downloadAndPlay(event?: MouseEvent): Promise<void> {
392+
async downloadAndPlayManually(event?: MouseEvent): Promise<void> {
394393
event?.preventDefault();
395394
event?.stopPropagation();
396395

@@ -407,51 +406,44 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv
407406
try {
408407
// Confirm the download if needed.
409408
await CoreAlerts.confirmDownloadSize({ size: this.deployedFile.filesize || 0, total: true });
409+
} catch (error) {
410+
return;
411+
}
410412

413+
await this.downloadAndPlay();
414+
}
415+
416+
/**
417+
* Download the file and play it.
418+
*/
419+
protected async downloadAndPlay(): Promise<void> {
420+
try {
411421
await this.downloadDeployedFile();
412422

413423
if (!this.isDestroyed) {
414424
this.play();
415425
}
416-
417426
} catch (error) {
418427
if (CoreErrorHelper.isCanceledError(error) || this.isDestroyed) {
419428
// User cancelled or view destroyed, stop.
420429
return;
421430
}
422431

423-
if (error instanceof CoreH5PMissingDependenciesError) {
424-
// Cannot be played offline, use online player.
425-
this.hasMissingDependencies = true;
426-
this.fileUrl = undefined;
427-
this.play();
428-
429-
CoreToasts.show({
430-
message: Translate.instant('core.course.activityrequiresconnection'),
431-
duration: ToastDuration.LONG,
432-
});
432+
if (CoreErrorHelper.isNetworkError(error)) {
433+
CoreAlerts.showError(error, { default: Translate.instant('core.errordownloading') });
433434

434435
return;
435436
}
436437

437-
CoreAlerts.showError(error, { default: Translate.instant('core.errordownloading') });
438-
}
439-
}
440-
441-
/**
442-
* Download the file automatically.
443-
*
444-
* @returns Promise resolved when done.
445-
*/
446-
protected async downloadAutomatically(): Promise<void> {
447-
try {
448-
await this.downloadDeployedFile();
438+
// Cannot download the file, use online player.
439+
this.hasMissingDependencies = error instanceof CoreH5PMissingDependenciesError;
440+
this.fileUrl = undefined;
441+
this.play();
449442

450-
if (!this.isDestroyed) {
451-
this.play();
452-
}
453-
} catch (error) {
454-
CoreAlerts.showError(error, { default: Translate.instant('core.errordownloading') });
443+
CoreToasts.show({
444+
message: Translate.instant('core.course.activityrequiresconnection'),
445+
duration: ToastDuration.LONG,
446+
});
455447
}
456448
}
457449

0 commit comments

Comments
 (0)