@@ -134,12 +134,6 @@ shaka.media.PreloadManager = class extends shaka.util.FakeEventTarget {
134
134
/** @private {!shaka.util.PublicPromise} */
135
135
this . successPromise_ = new shaka . util . PublicPromise ( ) ;
136
136
137
- /** @private {!shaka.util.PublicPromise} */
138
- this . destroyPromise_ = new shaka . util . PublicPromise ( ) ;
139
-
140
- // Silence promise failures, in case nobody is catching this.destroyPromise_
141
- this . destroyPromise_ . catch ( ( error ) => { } ) ;
142
-
143
137
/** @private {?shaka.util.FakeEventTarget} */
144
138
this . eventHandoffTarget_ = null ;
145
139
@@ -376,32 +370,30 @@ shaka.media.PreloadManager = class extends shaka.util.FakeEventTarget {
376
370
377
371
/**
378
372
* Starts the process of loading the asset.
379
- * @return { !Promise }
373
+ * Success or failure will be measured through waitForFinish()
380
374
*/
381
- async start ( ) {
382
- // Force a context switch, to give the player a chance to hook up events
383
- // immediately if desired.
384
- await Promise . resolve ( ) ;
385
-
386
- // Perform the preloading process.
387
- try {
388
- await this . parseManifestInner_ ( ) ;
389
- if ( this . isDestroyed ( ) ) {
390
- return ;
391
- }
392
- await this . initializeDrmInner_ ( ) ;
393
- if ( this . isDestroyed ( ) ) {
394
- return ;
395
- }
396
- await this . chooseInitialVariantInner_ ( ) ;
397
- if ( this . isDestroyed ( ) ) {
398
- return ;
375
+ start ( ) {
376
+ ( async ( ) => {
377
+ // Force a context switch, to give the player a chance to hook up events
378
+ // immediately if desired.
379
+ await Promise . resolve ( ) ;
380
+
381
+ // Perform the preloading process.
382
+ try {
383
+ await this . parseManifestInner_ ( ) ;
384
+ this . throwIfDestroyed_ ( ) ;
385
+
386
+ await this . initializeDrmInner_ ( ) ;
387
+ this . throwIfDestroyed_ ( ) ;
388
+
389
+ await this . chooseInitialVariantInner_ ( ) ;
390
+ this . throwIfDestroyed_ ( ) ;
391
+
392
+ this . successPromise_ . resolve ( ) ;
393
+ } catch ( error ) {
394
+ this . successPromise_ . reject ( error ) ;
399
395
}
400
- this . successPromise_ . resolve ( ) ;
401
- } catch ( error ) {
402
- this . destroyPromise_ . reject ( error ) ;
403
- throw error ;
404
- }
396
+ } ) ( ) ;
405
397
}
406
398
407
399
/**
@@ -423,7 +415,7 @@ shaka.media.PreloadManager = class extends shaka.util.FakeEventTarget {
423
415
onError ( error ) {
424
416
if ( error . severity === shaka . util . Error . Severity . CRITICAL ) {
425
417
// Cancel the loading process.
426
- this . destroyPromise_ . reject ( error ) ;
418
+ this . successPromise_ . reject ( error ) ;
427
419
this . destroy ( ) ;
428
420
}
429
421
@@ -435,6 +427,20 @@ shaka.media.PreloadManager = class extends shaka.util.FakeEventTarget {
435
427
}
436
428
}
437
429
430
+ /**
431
+ * Throw if destroyed, to interrupt processes with a recognizable error.
432
+ *
433
+ * @private
434
+ */
435
+ throwIfDestroyed_ ( ) {
436
+ if ( this . isDestroyed ( ) ) {
437
+ throw new shaka . util . Error (
438
+ shaka . util . Error . Severity . CRITICAL ,
439
+ shaka . util . Error . Category . PLAYER ,
440
+ shaka . util . Error . Code . OBJECT_DESTROYED ) ;
441
+ }
442
+ }
443
+
438
444
/**
439
445
* Makes a fires an event corresponding to entering a state of the loading
440
446
* process.
@@ -534,6 +540,7 @@ shaka.media.PreloadManager = class extends shaka.util.FakeEventTarget {
534
540
const event = this . makeEvent_ (
535
541
shaka . util . FakeEvent . EventName . TracksChanged ) ;
536
542
await Promise . resolve ( ) ;
543
+ this . throwIfDestroyed_ ( ) ;
537
544
this . dispatchEvent ( event ) ;
538
545
}
539
546
@@ -542,6 +549,7 @@ shaka.media.PreloadManager = class extends shaka.util.FakeEventTarget {
542
549
await this . drmEngine_ . initForPlayback (
543
550
playableVariants ,
544
551
this . manifest_ . offlineSessionIds ) ;
552
+ this . throwIfDestroyed_ ( ) ;
545
553
546
554
// Now that we have drm information, filter the manifest (again) so that
547
555
// we can ensure we only use variants with the selected key system.
@@ -692,10 +700,7 @@ shaka.media.PreloadManager = class extends shaka.util.FakeEventTarget {
692
700
* @export
693
701
*/
694
702
waitForFinish ( ) {
695
- return Promise . race ( [
696
- this . successPromise_ ,
697
- this . destroyPromise_ ,
698
- ] ) ;
703
+ return this . successPromise_ ;
699
704
}
700
705
701
706
/**
0 commit comments