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

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

Open
stevendesu opened this issue Aug 27, 2019 · 3 comments
Open

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

stevendesu opened this issue Aug 27, 2019 · 3 comments

Comments

@stevendesu
Copy link

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)

@tri170391
Copy link
Contributor

tri170391 commented Aug 27, 2019

Not sure which version are you using but you might be interested in #84 and #85

Anyway can you inform which version your fork is based on and on which browser it happens would be nice.

@stevendesu
Copy link
Author

My fork is based on v1.0.10

Even with those two pull requests, I don't know if it would fix the issue. When I look at the current master branch, I see the following for the _updateSelectedTextTrack function:

        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;
                }
            }

            var hlsjsTracks = _video.textTracks;
            for (var k = 0; k < hlsjsTracks.length; k++) {
                if (hlsjsTracks[k].kind === 'subtitles' || hlsjsTracks[k].kind === 'captions') {
                    hlsjsTracks[k].mode = activeTrack && _isSameTextTrack(hlsjsTracks[k], activeTrack) ? 'showing' : 'disabled';
                }
            }
        }

The key line here is:

            var hlsjsTracks = _video.textTracks;

This implies that _video.textTracks will have any valid information. However when a video does not support native text tracks, VideoJS overrides tech_.media.addTextTrack with its own method that only saves the tracks internally.

I've further seen that because HLS.js is not aware of VideoJS and it attempts to set the text track on the media element itself, this caused errors in Firefox (whose video.addTextTrack method has a slightly different signature from Chrome's, which HLS.js was tested on). Therefore in my own player I've had to write a small fix for this HLS.js issue:

if (!this.player.tech_.featuresNativeTextTracks)
{
	data.media.addTextTrack = (type, name, lang) => this.player.addTextTrack(type, name, lang);
}

@tri170391
Copy link
Contributor

tri170391 commented Aug 28, 2019

AFAIK the only "proper" solution here is to adapt Hls.js cue/text track handling to have it interact directly with video.js custom text track API. Our "intended" use cases are for HLS streams with native text tracks so the most logical implem is to hook video.js API for control and UI purpose only. (Say we inject "dummy" tracks to allow video.js UI to switch Hls.js injected-to-video-element native text tracks)

Anyway if you have any good and robust way to hook Hls.js text track handling (which you see in #85 may even comes up mid-stream, a.k.a CC tracks) to video.js that does not involve re-implementing what Hls.js does with HTML5 element's video text track it would be welcome. 😉

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

No branches or pull requests

2 participants