Skip to content

Subtitles only seem to work if native text tracks are supported #99

@stevendesu

Description

@stevendesu

VideoJS provides a _player.addTextTrack() method for devices and browsers which lack native text track support. When this method is utilized, _player.textTracks() will return a list of tracks, but _video.textTracks() will not return anything. This prevents _updateSelectedTextTrack from properly setting the track to "showing", and subtitles never display

In my fork I was able to fix this like so:

        function _updateSelectedTextTrack() {
            var playerTextTracks = _player.textTracks();
            var activeTrack = null;
            for (var j = 0; j < playerTextTracks.length; j++) {
                if (playerTextTracks[j].mode === 'showing') {
                    activeTrack = playerTextTracks[j];
                    break;
                }
            }

            if (activeTrack === null) {
                _hls.subtitleTrack = -1;
                return;
            }

            var hlsjsTracks = _hls.subtitleTracks;
            for (var k = 0; k < hlsjsTracks.length; k++) {
                if (hlsjsTracks[k].name === _getTextTrackLabel(activeTrack)) {
                    _hls.subtitleTrack = k;
                    break;
                }
            }
        }

Furthermore I replaced all instances of _video.textTracks with _player.textTracks() (which negated most of the _updateTextTrackList() method, as it was now comparing a list to itself)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions