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

Fixup tracks some more #2494

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 1 addition & 16 deletions src/js/tech/html5.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class Html5 extends Tech {

// If the original tag is still there, clone and remove it.
if (el) {
const clone = el.cloneNode(false);
const clone = el.cloneNode(true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is a deep clone necessary here (and not before)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise, we won't get tracks available on something like ios.
Previously, we'd grab all the tracks from the element and store them on the options object (which still happens) but then we need to pass it to the tech. However, if we pass through both that option and the textTracks object, if you swap between techs, you'll start getting duplicated tracks. So, instead, I can remove the need to pass through the tracks option to the tech and just clone the node with its sub nodes, since the tracks option should only have been used the first time the player was initialized.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully, that makes sense.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that makes sense.

el.parentNode.insertBefore(clone, el);
Html5.disposeMediaElement(el);
el = clone;
Expand All @@ -148,21 +148,6 @@ class Html5 extends Tech {
})
);
}

if (this.options_.tracks) {
for (let i = 0; i < this.options_.tracks.length; i++) {
const track = this.options_.tracks[i];
let trackEl = document.createElement('track');
trackEl.kind = track.kind;
trackEl.label = track.label;
trackEl.srclang = track.srclang;
trackEl.src = track.src;
if ('default' in track) {
trackEl.setAttribute('default', 'default');
}
el.appendChild(trackEl);
}
}
}

// Update specific tag settings, in case they were overridden
Expand Down