Implementation of TextTrackList
Please refer to this URL first if you did not read.
https://developer.mozilla.org/en-US/docs/Web/API/TextTrackList
It metioned that
addtrack
Fired when a new text track has been added to the media element.
removetrack
Fired when a new text track has been removed from the media element.
As you can see from the above, addtrack
and removetrack
events are dependent on HTMLMediaElement.
Remove track with DOM element .removeChild()
<!-- HTML -->
<video src="foo.ogv">
<track kind="subtitles" label="English subtitles" src="subtitles_en.vtt" srclang="en" default>
</track>
<track kind="subtitles" label="Deutsche Untertitel" src="subtitles_de.vtt" srclang="de">
</track>
</video>
videoElement.textTracks console output
var videoElement = document.querySelector("video");
console.log(videoElement.textTracks);
//output
TextTrackList {0: TextTrack, 1: TextTrack, length: 2, onchange: null, onaddtrack: null, onremovetrack: null}
0: TextTrack {kind: "subtitles", label: "English subtitles", language: "en", id: "", mode: "showing", …}
1: TextTrack {kind: "subtitles", label: "Deutsche Untertitel", language: "de", id: "", mode: "disabled", …}
length: 2
videoElement.textTracks.onremovetrack = function(event){
console.log('DOM removed',event)
console.log(videoElement.textTracks)
}
var tracks = videoElement.querySelectorAll('track')
videoElement.removeChild(tracks[0])
//output
DOM removed TrackEvent {isTrusted: true, track: TextTrack, type: "removetrack", target: TextTrackList, currentTarget: TextTrackList, …}
TextTrackList {0: TextTrack, 1: TextTrack, length: 1,...}
0: TextTrack {kind: "subtitles", label: "Deutsche Untertitel", language: "de", id: "", mode: "disabled", …}
Disable Track
videoElement.textTracks[0].mode = "disabled"; // Disable English
videoElement.textTracks[1].mode = "showing"; // Enable Deutsche
addTextTrack & removeTextTrack
addTextTrack
method will not create track element
to HTMLMediaElement, thus you need to create and append track element
manually if you need to remove a track using DOM element.
There is no removeTextTrack
method at the moment. If you need removeTextTrack
please visit the following as @Endless mentioned from the above comment. https://github.com/whatwg/html/issues/1921