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

Setting TextTrack to defaults not working when text track and video player are created dynamically. #4315

Closed
Pinank08 opened this issue Apr 29, 2017 · 5 comments

Comments

@Pinank08
Copy link

Pinank08 commented Apr 29, 2017

Description

I wan't to create a dynamic video player i.e. video src and caption src comes from different file on click event.

Steps to reproduce

Explain in detail the exact steps necessary to reproduce the issue.

  1. I have created a dynamic video player in videojs.
  2. Than to add text track I have used addRemoteTextTrack() function.
  3. But I am not able to make the track added as default as it always selects subtitle off as default.

Here is the code that I have used.

var oldTracks = player.remoteTextTracks();
  var i = oldTracks.length;
  while (i--) {
    player.removeRemoteTextTrack(oldTracks[i]);
  }

var trackk = new function() {
    this.kind = 'subtitles';
    this.label = 'english';
    this.language = 'en';
    this.id='track1';
    this.src = url+'.vtt';
    this.default= 'true'; // i have tried default too
}
    player.addRemoteTextTrack(trackk, true);

/*  I have used 
player.TextTrack = 'default';
player.TextTracks.mode='showing';
and many more... but subtitles are always off bydefault
*/ 

Results

Expected

I Expect to see subtitles when video is loaded.

Actual

When Video is loaded subtitles are off.

@Pinank08 Pinank08 changed the title Setting TextTrack it to defaults not working when text track and video player are created dynamically. Setting TextTrack to defaults not working when text track and video player are created dynamically. Apr 29, 2017
@jthomerson
Copy link

@Pinank08 please see my description in #4403. Are you using version 6.x? If so, please let us know because your problem is likely caused by #4403. Can you try the workarounds I show in that example to see if they fix your issue?

gkatsev added a commit that referenced this issue Jun 28, 2017
…to (#4450)

We added a feature so that remote text tracks can auto-removed when a source changes. However, in 6.x we changed the source behavior to be asynchronous meaning that some text tracks were accidentally being removed when they weren't supposed to be.
For example:
```js
var player = videojs('my-player');
player.src({src: 'video.mp4', type: 'video/mp4'});
 // set second arg to false so that they get auto-removed on source change
player.addRemoteTextTrack({kind: 'captions', src: 'text.vtt', srclang: 'en'}, false);
```
Now when the player loads, this captions track is actually missing because it was removed.

Instead of adding auto-removal tracks immediately to the list, wait until we've selected a source before adding them in.


Fixes #4403 and #4315.
@gkatsev
Copy link
Member

gkatsev commented Dec 4, 2017

Closing as potentially fixed and due to lack of activity. If we get more information, we can re-open.

@gkatsev gkatsev closed this as completed Dec 4, 2017
@partap
Copy link

partap commented Jan 27, 2018

I am having this problem with version 6.6.2.

Actually, I have the video and a default track loaded initially with HTML tags, and the track is selected by default...this works fine. The page implements a very rudimentary subtitle editor...for now, any time a cue is edited, it deletes the entire TextTrack and reloads it using Player.removeTrack() and Player.addRemoteTextTrack(). This is also working, except when the new track is loaded with default: true option set, it remains unselected in the player until I click it in the menu.

The documentation is not clear as to how to activate a loaded TextTrack from Javascript, other than setting default: true

@partap
Copy link

partap commented Jan 27, 2018

I just spent a while stepping through with devtools... it looks like the property that is affected by selecting the text track from the menu is mode, which toggles between 'disabled' and 'showing'

So, if I pass the option mode: 'showing' to addRemoteTextTrack(), it works. The mode parameter in the documentation could use a little touch-up...

...I'm actually seeing the TextTrack.mode constants specified at MDN, now that I know... but I didn't realize it was just standard DOM.

@pegasus1982
Copy link

@partap Thanks man.
I followed your way, and finally I could resolve my issue.
But I still can't know why it happens when I use that option.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants