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

Consider Exporting videojs.MenuButton #647

Closed
dominic-p opened this issue Jul 19, 2013 · 16 comments
Closed

Consider Exporting videojs.MenuButton #647

dominic-p opened this issue Jul 19, 2013 · 16 comments

Comments

@dominic-p
Copy link
Contributor

I'm working on a plugin that will add a new menu style button similar to the captions button. All of the other properties I need seem to be available (e.g. videojs.MenuItem), but videojs.MenuButton isn't exposed.

I'm sure I could recreate the functionality by extending videojs.Button, but that would mean a lot of copy/pasting from the core. Any reason not to export videojs.MenuButton that I'm missing?

@heff
Copy link
Member

heff commented Jul 19, 2013

No, that was an oversight. If you make a pull request to add it to exports I'll pull it in.
https://github.com/videojs/video.js/blob/master/src/js/exports.js

On Jul 19, 2013, at 1:09 AM, Dominic [email protected] wrote:

I'm working on a plugin that will add a new menu style button similar to the text tracks. All of the other properties I need seem to be available (e.g. videojs.MenuItem), but videojs.MenuButton isn't exposed.

I'm sure I could recreate the functionality by extending videojs.Button, but that seems less than ideal. Any reason not to export videojs.MenuButton that I'm missing?


Reply to this email directly or view it on GitHub.

dominic-p added a commit to dominic-p/video.js that referenced this issue Jul 19, 2013
Allows for plugins to create menu style buttons. See videojs#647.
@dominic-p
Copy link
Contributor Author

This might not be as simple as I thought actually. When creating the menu items, you have to call new videojs.MySpecialMenuItem(), but in the context of the createItems function you don't have a readily accessible player object to pass to the constructor of videojs.MenuItem(). In the core, there's this.player_, but that is obfuscated when plugins run.

Of course, I could add the player object as a property on my plugin's videojs.MenuButton, but that would mean duplicating it, and I don't know what issues that might create (performance?). Or, I could call my own create items function, pass it the player object and then manually call menu.addItem() for each item, but that would mean duplicating some core functionality.

Am I missing something here, or should I just suck it up and use one of the work-arounds above?

@heff
Copy link
Member

heff commented Jul 22, 2013

Anywhere this.player_ exists there should also be this.player() exposed. Have you tried using that to reference the player?

@heff heff closed this as completed in a38ce63 Jul 22, 2013
@dominic-p
Copy link
Contributor Author

Ahh, I missed this.player(), thanks for pointing that out.

@heff
Copy link
Member

heff commented Jul 23, 2013

No problem

On Jul 22, 2013, at 6:41 PM, Dominic [email protected] wrote:

Ahh, I missed this.player(), thanks for pointing that out.


Reply to this email directly or view it on GitHub.

@dominic-p
Copy link
Contributor Author

@heff, sorry to resurrect a dead issue, but I think I spoke too soon. I was developing using the unminified source before, but when I tested it on the minified version, this.player() was nowhere to be found.

I tried adding it to exports.js and it still came up undefined. This might be related to the issues I'm having building the project, but I'm not sure. It's almost as if, the subclasses aren't inheriting the player() function from vjs.Component. And, when I call videojs.Component.prototype.player (exactly as I exported it) I get a property undefined error. Strange.

heff added a commit that referenced this issue Jul 29, 2013
@heff
Copy link
Member

heff commented Jul 29, 2013

It looks like component.player was never exported. Just exported. Try it now?

@dominic-p
Copy link
Contributor Author

Thanks for taking a look. For some reason this.player() is still undefined where I'm trying to use it. I need a player reference at two points in my code. First, when I define the MenuItems, and second when I define the click behaviors for the menu items. In both contexts, this.player() is not defined.

I would think that both of those classes should inherit the player function from vjs.Component, but they don't for some reason. As you can see, it's easy enough to work around the issue for now by just copying the player object to a class property in the init functions, but that doesn't seem right to me. Thoughts?

@heff
Copy link
Member

heff commented Jul 29, 2013

Ok, I'm probably gonna need you show a full example of what you're doing. I just ran the following test and player() was available in both instances.

  videojs.TestComp = videojs.Component.extend({
    init: function(player, options){
      videojs.Component.call(this, player, options);

      ok(this.player());
    }
  });

  var asdf = new videojs.TestComp(player);
  ok(asdf.player());

@dominic-p
Copy link
Contributor Author

That's interesting. In your first test, does the this.player() return undefined? That's what I'm getting, but that doesn't seem wrong given that a player hasn't been setup yet.

Did you have a chance to look at the 2 bits of code I linked in the previous message? That would be my full example. On both of those lines, I would like to change this.player to this.player(), but for some reason the function isn't defined in that context. I'll try to work up a more stripped down example. I'll post an update when I have that ready.

@heff
Copy link
Member

heff commented Jul 30, 2013

This line could be breaking it. It's overwriting the player() method with a static ref to player.
https://github.com/dominic-p/videojs-resolution-selector/blob/v0.9/video-quality-selector.js#L165

@heff
Copy link
Member

heff commented Jul 30, 2013

Same with this one.
https://github.com/dominic-p/videojs-resolution-selector/blob/v0.9/video-quality-selector.js#L76

When you run the super init _V_.MenuItem.call() it will eventually run the Component init which makes player() work, but before that's called player() won't return anything. And if you override this.player manually, this.player() will never work.

@dominic-p
Copy link
Contributor Author

Oh man, I feel dumb. That was it. Thanks for taking the time to discover that. I really appreciate it. The code is working as expected now.

@heff
Copy link
Member

heff commented Jul 30, 2013

Awesome! No problem.

@raidpipe
Copy link

raidpipe commented Sep 9, 2015

hello guys i am about to add resolution selector to my site having video.js player, do i need to create different copies for each video resolution ???

@dominic-p
Copy link
Contributor Author

@raidpipe, take a look at the example file for the plugin. You should setup your video files to match that.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 27, 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

3 participants