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

Persist caption/description choice over source changes #4295

Merged
merged 10 commits into from May 25, 2017

Conversation

ldayananda
Copy link
Contributor

@ldayananda ldayananda commented Apr 19, 2017

Description

This should allow a user's choice of subtitle or description to be respected across an entire session(if available).

Specific Changes proposed

  • Remember the user selection
  • User selected choice is preferred over the first default track

Requirements Checklist

  • Feature implemented / Bug fixed
  • If necessary, more likely in a feature request than a bug fix
    • Change has been verified in an actual browser (Chome, Firefox, IE)
    • Unit Tests updated or fixed
    • Docs/guides updated (n/a)
  • Reviewed by Two Core Contributors

Copy link
Member

@gkatsev gkatsev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love the tests.
We have method called reset that tries to bring the player to as close to an un-initialized state as possible, should it also unset the selectedLanguage?

player.dispose();
});

QUnit.test('no captions tracks, no captions are displayed', function(assert) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like this is a SubsCapsButton test rather than a TextTrackDisplay test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right! Turns out there's a test like this in text-track-controls.test.js already which I will expand to check if remoteTextTracks is empty as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remoteTextTracks should never have stuff in it if textTracks is already empty.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh nice, will just remove this one then.

});

if (!Html5.supportsNativeTextTracks()) {
QUnit.test('if user-selected language is unavailable, don\'t pick a track to show', function(assert) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe our eslint rules allow us to use double-quotes in this situation to avoid escaping the quote.

}
};

QUnit.test('if native text tracks are not supported, create a texttrackdisplay', function(assert) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for reference, this test was moved from text-tracks.test.js

src: 'es.vtt'
};

browser.IS_FIREFOX = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why force firefox?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I don't actually need this if I check supportsNativeTextTracks

this.clock.tick(1);

// the spanish captions track should be shown
const englishTrack = getTrackByLanguage(player, 'en');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

player.addRemoteTextTrack returns an HTMLTrackElement (or a shim) that has the track in a .track property. That might be another way of getting it rather than getTrackByLanguage, if that's the only places that getTrackByLanguage is used.

}
break;
}

if (track.default) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be an else if for the above if?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, will update


// The user chooses Spanish
player.play();
captionsButton.pressButton();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably no need to press the captions button.

@gkatsev
Copy link
Member

gkatsev commented Apr 19, 2017

Also, it's great that the non-code changes are pretty small and fairly localized!

@ldayananda
Copy link
Contributor Author

Updated code and tests according to the feedback above. We decided that the reset method should continue to behave as it does currently and selectedLanguage will remain set if reset is called.

item.addClass(`vjs-${track.kind}-menu-item`);
items.push(item);
}
}

if (preferredItem) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couldn't this have the side-effect of switching the selected track when a new track is added? Also, this seems like it'll try and enable a track per text-track-button.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes and yes. Back to the drawing board :)

@ldayananda
Copy link
Contributor Author

Updated once again, this time with more encapsulation

@gkatsev gkatsev added this to Ready to Review in video.js May 8, 2017
Copy link
Member

@gkatsev gkatsev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good and I think it's good enough to go to QA.

Though, I'd like to take play around with it a bit myself as well.

@@ -92,6 +92,7 @@ class TextTrackDisplay extends Component {

player.on('loadstart', Fn.bind(this, this.toggleDisplay));
player.on('texttrackchange', Fn.bind(this, this.updateDisplay));
player.on('loadstart', Fn.bind(this, this.preselectTrack));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did we decide on whether we wanted this to happen on addtrack as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that we discussed it and decided that it would be disorienting to preselect a new track if a track had already been selected by the user.


if (nonLanguageTextTrackKind.indexOf(track.kind) === -1) {
track.addEventListener('modechange', Fn.bind(this, function() {
this.trigger('selectedlanguagechange');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just realized it's possible that the language doesn't change, so, the naming is a big weird, but maybe still ok.
For example, if you go from english captions to english subtitles, the language is the same but only the kind changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe displayedtexttrackchange would be a better name?

@gkatsev gkatsev moved this from Ready to Review to Ready for testing in video.js May 8, 2017
@apadhye
Copy link

apadhye commented May 18, 2017

QA LGTM

@gkatsev gkatsev merged commit 188ead1 into videojs:master May 25, 2017
@ldayananda ldayananda deleted the persist-caption branch August 23, 2017 02:28
@gkatsev gkatsev moved this from Ready for testing to Done in video.js Jun 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

None yet

4 participants