Turning off subtitling is not clean
Created by: TobbeMobiTV
setTextTrack in TextSourceBuffer loops over text tracks as there is a change. If a new track is in mode "showing", it tidies up things and clears the old track. However, it does not do anything when there is no longer any track showing.
I think the code should rather look something like below, but I lack the proper call to the mediaController to tell that there is no track active right now, so I haven't made a PR.
setTextTrack = function() {
var el = this.videoModel.getElement(),
tracks = el.textTracks,
ln = tracks.length,
self = this,
previousTrackIdx = self.textTrackExtensions.getCurrentTrackIdx(),
newTrackIdx = -1;
for (var i = 0; i < ln; i++ ) {
var track = tracks[i];
if (track.mode === "showing") {
newTrackIdx = i;
break;
}
}
console.log("TOBBE index " + previousTrackIdx + " " + newTrackIdx);
if (newTrackIdx !== previousTrackIdx) {
if (previousTrackIdx !== -1) {
var previousTextTrack = tracks[previousTrackIdx];
if (previousTextTrack !== null) {
self.textTrackExtensions.deleteTrackCues(previousTextTrack);
if (previousTextTrack.renderingType === "html") {
self.textTrackExtensions.removeNativeCueStyle();
self.textTrackExtensions.clearCues();
}
}
self.fragmentModel.cancelPendingRequests();
self.fragmentModel.abortRequests();
self.buffered.clear();
}
self.textTrackExtensions.setCurrentTrackIdx(newTrackIdx);
if (newTrackIdx !== -1) {
self.mediaController.setTrack(self.allTracks[newTrackIdx]);
} else {
// I'm missing the right thing to do here to tell the mediaController that no track is active
}
}
};