@@ -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