@sumaris-net/ngx-components 2.4.69 → 2.4.71

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10497,17 +10497,25 @@ class AudioProvider extends StartableService {
10497
10497
  this._audioType = cordova && Capacitor.isPluginAvailable('NativeAudio') ? 'native' : 'html5';
10498
10498
  console.info(`[audio] Starting audio provider {${this._audioType}}...`);
10499
10499
  // Listen audio mode changed
10500
- if (this.platform.is('cordova') && this.audioManagement) {
10500
+ if (cordova && this.audioManagement) {
10501
10501
  await this.readAudioMode();
10502
10502
  }
10503
10503
  // Pre-loading system sounds
10504
10504
  console.debug('[audio] Preloading audio sounds...');
10505
+ let errorCount = 0;
10505
10506
  await Promise.all(SYSTEM_SOUNDS.map(s => {
10506
10507
  // Disable vibration in HTML 5 mode
10507
10508
  if (this._audioType === 'html5')
10508
10509
  s.vibration = undefined;
10509
- return this.preload(s);
10510
+ return this.preload(s)
10511
+ .catch(_ => errorCount++);
10510
10512
  }));
10513
+ if (errorCount > 0) {
10514
+ console.warn('[audio] Preloading audio sounds [OK] with ${errorCount} errors during preload.');
10515
+ }
10516
+ else {
10517
+ console.debug('[audio] Preloading audio sounds [OK]');
10518
+ }
10511
10519
  }
10512
10520
  playBeepConfirm() {
10513
10521
  return this.play('beep-confirm', {
@@ -10530,10 +10538,14 @@ class AudioProvider extends StartableService {
10530
10538
  return this.play('startup');
10531
10539
  }
10532
10540
  async preload(sound) {
10541
+ if (!sound?.assetId)
10542
+ return; // Skip
10543
+ if (!!this._preloadedSounds[sound.assetId])
10544
+ return; // Already preloaded
10533
10545
  if (isNil(this._audioType))
10534
10546
  await this.ready();
10535
10547
  const assetPath = (this._assetPathPrefix || '') + sound.assetPath;
10536
- console.info(`[audio] Preloading audio file '${assetPath}'...`);
10548
+ console.info(`[audio] Preloading sound '${sound.assetId}', from file '${assetPath}'...`);
10537
10549
  try {
10538
10550
  if (this._audioType === 'native') {
10539
10551
  await NativeAudio.preload({
@@ -10548,10 +10560,17 @@ class AudioProvider extends StartableService {
10548
10560
  }
10549
10561
  // Add to map
10550
10562
  this._preloadedSounds[sound.assetId] = sound;
10551
- console.info(`[audio] Preloading audio file '${assetPath}' [OK]`);
10563
+ console.info(`[audio] Preloading sound '${sound.assetId}' [OK]`);
10552
10564
  }
10553
10565
  catch (err) {
10554
- console.error(`[audio] Unable to preload audio file '${assetPath}': ${err && err.message || err}\n${err?.originalStack}`);
10566
+ const errorMsg = err?.message || err;
10567
+ if (errorMsg === 'Audio Asset already exists') {
10568
+ console.info(`[audio] Preloading sound '${sound.assetId}': Skipped (${errorMsg})`);
10569
+ }
10570
+ else {
10571
+ console.error(`[audio] Unable to preload sound '${sound.assetId}', from file '${assetPath}': ${errorMsg}\n${err?.originalStack || ''}`);
10572
+ throw err;
10573
+ }
10555
10574
  }
10556
10575
  }
10557
10576
  async play(assetId, opts) {
@@ -10560,7 +10579,7 @@ class AudioProvider extends StartableService {
10560
10579
  await this.ready();
10561
10580
  const sound = this._preloadedSounds[assetId];
10562
10581
  if (!sound) {
10563
- throw Error(`Unable to find audio with id '${assetId}'. Please call preload() before playing a sound.`);
10582
+ throw Error(`Unable to find sound '${assetId}'. Please call preload() before playing a sound.`);
10564
10583
  }
10565
10584
  // If silent: skip
10566
10585
  if (this._audioMode === AudioManagement.AudioMode.SILENT)