Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix exceptions when quickly shutting down src= on Safari #4088

Merged
merged 1 commit into from Mar 31, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 26 additions & 11 deletions lib/player.js
Expand Up @@ -2217,6 +2217,14 @@ shaka.Player = class extends shaka.util.FakeEventTarget {

this.playhead_ = new shaka.media.SrcEqualsPlayhead(has.mediaElement);

// This flag is used below in the language preference setup and
// track-management to check if this load was canceled before the necessary
// events fired.
let unloaded = false;
this.cleanupOnUnload_.push(() => {
unloaded = true;
});

if (has.startTime != null) {
this.playhead_.setStartTime(has.startTime);
}
Expand Down Expand Up @@ -2268,6 +2276,12 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
}
if (this.video_.textTracks) {
this.eventManager_.listen(this.video_.textTracks, 'addtrack', (e) => {
// If we have moved on to another piece of content while waiting for
// the above event, we should not process tracks here.
if (unloaded) {
return;
}

const trackEvent = /** @type {!TrackEvent} */(e);
if (trackEvent.track) {
const track = trackEvent.track;
Expand Down Expand Up @@ -2327,13 +2341,6 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
fullyLoaded.resolve();
});

// This flag is used below in the language preference setup to check if this
// load was canceled before the necessary events fire.
let unloaded = false;
this.cleanupOnUnload_.push(() => {
unloaded = true;
});

// We can't switch to preferred languages, though, until the data is loaded.
shaka.util.MediaReadyState.waitForReadyState(this.video_,
HTMLMediaElement.HAVE_CURRENT_DATA,
Expand Down Expand Up @@ -2488,12 +2495,16 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
// In Safari the initial assignment does not always work, so we schedule
// this process to be repeated several times to ensure that it has been put
// in the correct mode.
new shaka.util.Timer(() => {
const timer = new shaka.util.Timer(() => {
const textTracks = this.getMetadataTracks_();
for (const textTrack of textTracks) {
textTrack.mode = 'hidden';
}
}).tickNow().tickAfter(/* seconds= */ 0.5);
}).tickNow().tickAfter(0.5);

this.cleanupOnUnload_.push(() => {
timer.stop();
});
}


Expand Down Expand Up @@ -2561,12 +2572,16 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
// In Safari the initial assignment does not always work, so we schedule
// this process to be repeated several times to ensure that it has been put
// in the correct mode.
new shaka.util.Timer(() => {
const timer = new shaka.util.Timer(() => {
const chaptersTracks = this.getChaptersTracks_();
for (const chaptersTrack of chaptersTracks) {
chaptersTrack.mode = 'hidden';
}
}).tickNow().tickAfter(/* seconds= */ 0.5);
}).tickNow().tickAfter(0.5);

this.cleanupOnUnload_.push(() => {
timer.stop();
});
}

/**
Expand Down