You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`setup` is called just after the player is created. This allows:
44
+
* plugin or custom functionalify to intialize on the player
45
+
* changes to the player object itself
46
+
47
+
`setup` hook functions:
48
+
* Take one argument
49
+
* player: the player that video.js created
50
+
* Don't have to return anything
51
+
52
+
Example: adding setup hook
53
+
```js
54
+
varsetup=function(player) {
55
+
// initialize the foo plugin
56
+
player.foo();
57
+
};
58
+
varfoo=function() {};
59
+
60
+
videojs.plugin('foo', foo);
61
+
videojs.hook('setup', setup);
62
+
var player =videojs('some-id', {autoplay:true, controls:true});
63
+
```
64
+
65
+
## Usage
66
+
67
+
### Adding
68
+
In order to use hooks you must first include video.js in the page or script that you are using. Then you add hooks using `videojs.hook(<name>, function)` before running the `videojs()` function.
// player will be the same player that is defined below
78
+
// as `var player`
79
+
});
80
+
var player =videojs('vid1', {autoplay:false});
81
+
```
82
+
83
+
After adding your hooks they will automatically be run at the correct time in the video.js lifecycle.
84
+
85
+
### Getting
86
+
To access the array of hooks that currently exists and will be run on the video.js object you can use the `videojs.hooks` function.
87
+
88
+
Example: getting all hooks attached to video.js
89
+
```js
90
+
var beforeSetupHooks =videojs.hooks('beforesetup');
91
+
var setupHooks =videojs.hooks('setup');
92
+
```
93
+
94
+
### Removing
95
+
To stop hooks from being executed during the video.js lifecycle you will remove them using `videojs.removeHook`.
96
+
97
+
Example: remove a hook that was defined by you
98
+
```js
99
+
varbeforeSetup=function(videoEl, options) {};
100
+
101
+
// add the hook
102
+
videojs.hook('beforesetup', beforeSetup);
103
+
104
+
// remove that same hook
105
+
videojs.removeHook('beforesetup', beforeSetup);
106
+
```
107
+
108
+
You can also use `videojs.hooks` in conjunction with `videojs.removeHook` but it may have unexpected results if used during an asynchronous callbacks as other plugins/functionality may have added hooks.
109
+
110
+
Example: using `videojs.hooks` and `videojs.removeHook` to remove a hook
0 commit comments