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

TextTracks - Not cleaning up upon detachment #2198

Closed
5 tasks done
michaelcunningham19 opened this issue Mar 27, 2019 · 10 comments · Fixed by #2432
Closed
5 tasks done

TextTracks - Not cleaning up upon detachment #2198

michaelcunningham19 opened this issue Mar 27, 2019 · 10 comments · Fixed by #2432

Comments

@michaelcunningham19
Copy link
Member

What version of Hls.js are you using?

0.12.4

What browser and OS are you using?

Chrome 73 on macOS

Test stream:

https://hls-js.netlify.com/demo/?src=https%3A%2F%2Fwowzaec2demo.streamlock.net%2Fvod-multitrack%2F_definst_%2Fsmil%3AElephantsDream%2Felephantsdream2.smil%2Fplaylist.m3u&demoConfig=eyJlbmFibGVTdHJlYW1pbmciOnRydWUsImF1dG9SZWNvdmVyRXJyb3IiOnRydWUsImVuYWJsZVdvcmtlciI6dHJ1ZSwiZHVtcGZNUDQiOmZhbHNlLCJsZXZlbENhcHBpbmciOi0xLCJsaW1pdE1ldHJpY3MiOi0xLCJ3aWRldmluZUxpY2Vuc2VVcmwiOiIifQ==

Checklist

Steps to reproduce

  1. Open the test stream permalink above. Once playback begins, enable one of the subtitles tracks
  2. In the browser console, run hls.destroy()
  3. Observe the video element's TextTrackList is still populated with tracks and cues, see below screenshot.
  4. Switch to test stream to 'CNN special report, with CC``
  5. Observe text tracks from the previous playback session still exist and are selectable.

Expected behavior

I would expect that as part of the detaching phase, the TextTrackList would also be cleaned up / reset. At least having hls.js clean up what it created, to the best of its ability.

Actual behavior

It's left as-is, leaving tracks (which is expected, no way to remove them) and their cues in place. This can cause odd behaviour with switching between content.

Console output

See screenshot:
Screenshot 2019-03-27 13 40 40

@OrenMe
Copy link
Collaborator

OrenMe commented May 4, 2019

unfortunately there's no removeTextTrack in the HTMLVideoElement spec, so removing any text track created with addTextTrack is not possible.
See whatwg/html#1921 and whatwg/html#2881 for more details.

@hvgotcodes
Copy link

What's the recommendation here? Recreate video element for every play back?

@OrenMe
Copy link
Collaborator

OrenMe commented Oct 27, 2019

Currently yes.

@OrenMe
Copy link
Collaborator

OrenMe commented Oct 27, 2019

@michaelcunningham19 as this is web platform limitation I suggest we close this.

@itsjamie
Copy link
Collaborator

@OrenMe could hls.js clean up the cues?

@itsjamie
Copy link
Collaborator

Actually, with Chrome on Windows using 0.12.4 I can't reproduce this issue anymore. Looking into this...

@itsjamie
Copy link
Collaborator

So, these are the text tracks from a previous play. The timeline-controller will clean up the cues between media detachment. See the clearCurrentCues util being used. However, VTT cues like the ones from Angel-One sample are not cleaned up on media detachment.

@jimmywarting
Copy link

what if instead of adding a track programmatically with video.addTextTrack() we add a <track> element to the <video> element? the src could be a blob url? or left out?

then we can remove the <track> element to clear the track list, would that be possible?

@robwalch
Copy link
Collaborator

robwalch commented Jan 16, 2021

@jimmywarting That may work well in some or even most browsers, but it is not a good path forward for hls.js. We should maintain a policy of not modifying DOM tree structure in this project. Manipulating HTMLMediaElement.textTracks TextTrackList via HTMLMediaElement TextTrackElement children is very likely inconsistent across browsers especially on older platforms. For one, we can't use track src with segmented captions. We would need to wait for an event that surfaces the TextTrack instance in a TextTrackList before we could append cues to it after manipulating the media element children. And what if that doesn't happen in some browsers? Can we be sure the CC menu controls will reflect those changes? Will the mode (disabled, hidden, showing) of these tracks default to a value we do not want them to?

Give it a try https://jsfiddle.net/tgwvey8d/4/ sort of works in Chrome but if I chose a CC from the menu, the menu or toggle then disappears. Not in Safari, but for me track 1 defaults to on without any mode setting on tracks (Safari does some weird stuff automatically based on system-level preferences that can be toggled in the touch bar or system settings).

You can disable hls.js's textTrack manipulation via renderTextTracksNatively and then use NON_NATIVE_TEXT_TRACKS_FOUND and CUES_PARSED to add tracks and cues as is best for your application.

If you'd like to continue the conversation or suggest/contribute a change, please create a new issue as this one is closed. The demo currently suffers from this issue in some respects and does not demonstrate the suggested workaround of replacing the video element when necessary, so I would happily accept a new issue that points that out specifically.

@jimmywarting
Copy link

You can disable hls.js's textTrack manipulation via renderTextTracksNatively and then use NON_NATIVE_TEXT_TRACKS_FOUND and CUES_PARSED to add tracks and cues as is best for your application.

Nah, i like the native tracks. it haven bother me yet that they still exist.

I know the spec lacks the remove functionality. I just wanted to suggest a possible workaround if it even was possible/feasible.
Guess we have to wait 3 more years until someone else to quote "pick up the torch" on finishing the spec/standard

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants