Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
</ion-item>

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

Expand Down
56 changes: 24 additions & 32 deletions src/addons/mod/h5pactivity/components/index/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv
this.deployedFile?.filesize &&
CoreFilepool.shouldDownload(this.deployedFile.filesize)
) {
// Package is small, download it automatically. Don't block this function for this.
this.downloadAutomatically();
// Package is small, download and play it automatically. Don't block this function for this.
this.downloadAndPlay();
}
}

Expand Down Expand Up @@ -388,9 +388,8 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv
* Download the file and play it.
*
* @param event Click event.
* @returns Promise resolved when done.
*/
async downloadAndPlay(event?: MouseEvent): Promise<void> {
async downloadAndPlayManually(event?: MouseEvent): Promise<void> {
event?.preventDefault();
event?.stopPropagation();

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

await this.downloadAndPlay();
}

/**
* Download the file and play it.
*/
protected async downloadAndPlay(): Promise<void> {
try {
await this.downloadDeployedFile();

if (!this.isDestroyed) {
this.play();
}

} catch (error) {
if (CoreErrorHelper.isCanceledError(error) || this.isDestroyed) {
// User cancelled or view destroyed, stop.
return;
}

if (error instanceof CoreH5PMissingDependenciesError) {
// Cannot be played offline, use online player.
this.hasMissingDependencies = true;
this.fileUrl = undefined;
this.play();

CoreToasts.show({
message: Translate.instant('core.course.activityrequiresconnection'),
duration: ToastDuration.LONG,
});
if (CoreErrorHelper.isNetworkError(error)) {
CoreAlerts.showError(error, { default: Translate.instant('core.errordownloading') });

return;
}

CoreAlerts.showError(error, { default: Translate.instant('core.errordownloading') });
}
}

/**
* Download the file automatically.
*
* @returns Promise resolved when done.
*/
protected async downloadAutomatically(): Promise<void> {
try {
await this.downloadDeployedFile();
// Cannot download the file, use online player.
this.hasMissingDependencies = error instanceof CoreH5PMissingDependenciesError;
this.fileUrl = undefined;
this.play();

if (!this.isDestroyed) {
this.play();
}
} catch (error) {
CoreAlerts.showError(error, { default: Translate.instant('core.errordownloading') });
CoreToasts.show({
message: Translate.instant('core.course.activityrequiresconnection'),
duration: ToastDuration.LONG,
});
}
}

Expand Down
Loading