Skip to content

Commit e2d10f3

Browse files
committed
tracks_store: subtly different error handling
1 parent ad128b5 commit e2d10f3

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

src/main_thread/tracks_store/tracks_store.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ export default class TracksStore extends EventEmitter<ITracksStoreEvents> {
198198
if (this._isDisposed) {
199199
return; // Someone disposed the `TracksStore` on the previous side-effect
200200
}
201+
this.dispose();
202+
return;
201203
} else if (this.onTracksNotPlayableForType[ttype] === "continue") {
202204
// audio or video is not playable, but let's continue the playback without audio
203205
// or without video because of the option was set to "continue".
@@ -238,6 +240,9 @@ export default class TracksStore extends EventEmitter<ITracksStoreEvents> {
238240
["audio" as const, "video" as const].forEach((ttype) => {
239241
this.checkPeriodHasSupportedTrack(period, ttype);
240242
});
243+
if (this._isDisposed) {
244+
return;
245+
}
241246
}
242247

243248
let newPListIdx = 0;
@@ -600,7 +605,7 @@ export default class TracksStore extends EventEmitter<ITracksStoreEvents> {
600605
}
601606
this.trigger("error", noRepErr);
602607
this.dispose();
603-
return noPlayableTrackToTrigger;
608+
return [];
604609
}
605610
let typeInfo = getPeriodItem(this._storedPeriodInfo, period.id)?.[trackType];
606611
if (isNullOrUndefined(typeInfo)) {
@@ -644,6 +649,26 @@ export default class TracksStore extends EventEmitter<ITracksStoreEvents> {
644649
if (isNullOrUndefined(typeInfo) || typeInfo.storedSettings !== storedSettings) {
645650
return noPlayableTrackToTrigger;
646651
}
652+
653+
// Check that we're not both disabling audio and video here
654+
if (storedSettings === null) {
655+
const periodItem = getPeriodItem(this._storedPeriodInfo, period.id);
656+
if (periodItem !== undefined) {
657+
const hasNoTrackAtAll = ["audio" as const, "video" as const].every(
658+
(ttype) => periodItem[ttype].storedSettings === null,
659+
);
660+
if (hasNoTrackAtAll) {
661+
const err = new MediaError(
662+
"NO_AUDIO_VIDEO_TRACKS",
663+
"No audio and no video tracks are set.",
664+
);
665+
this.trigger("error", err);
666+
this.dispose();
667+
return [];
668+
}
669+
}
670+
}
671+
647672
typeInfo.dispatcher?.updateTrack(storedSettings);
648673
return noPlayableTrackToTrigger;
649674
}
@@ -1067,6 +1092,8 @@ export default class TracksStore extends EventEmitter<ITracksStoreEvents> {
10671092
"No audio and no video tracks are set.",
10681093
);
10691094
this.trigger("error", err);
1095+
this.dispose();
1096+
return;
10701097
}
10711098
}
10721099
}
@@ -1453,6 +1480,9 @@ export default class TracksStore extends EventEmitter<ITracksStoreEvents> {
14531480
trackStorePeriod.noPlayableTrackEventToDispatch.push(
14541481
...this.onNoPlayableRepresentation(period, "audio"),
14551482
);
1483+
if (this._isDisposed) {
1484+
return;
1485+
}
14561486
} else {
14571487
trackStorePeriod.audio.storedSettings = {
14581488
adaptation: audioAdaptation,
@@ -1468,6 +1498,9 @@ export default class TracksStore extends EventEmitter<ITracksStoreEvents> {
14681498
trackStorePeriod.noPlayableTrackEventToDispatch.push(
14691499
...this.onNoPlayableRepresentation(period, "video"),
14701500
);
1501+
if (this._isDisposed) {
1502+
return;
1503+
}
14711504
} else {
14721505
const videoAdaptation = getRightVideoTrack(
14731506
baseVideoAdaptation,

0 commit comments

Comments
 (0)