The Node object represents a chunk of video.
It is the primary currency of the InterludePlayer. It’s used with the playlist and the repository.
Creating a node instance is simply a matter of calling repository.add.
To get a reference to a node instance, call repository.get.
- Table of Contents
- Properties
- duration pro
- Methods
- on m
- off m
- once m
- trigger m
- addPrefetch m
- removePrefetch m
- Events
- nodestart e
- nodeend e
- nodecritical e
- playlistpush e
- timeupdate e
- Properties
Properties
node.duration : number
The duration of the node in seconds.
Example
var node = player.playlist[0];
console.log('Node duration is', node.duration);
Methods
node.on(evt, listener)
Adds a listener function to the specified event on the node.
If the listener function returns true then it will be removed after it is called.
If you pass a regular expression as the event name then the listener will be added to all events that match it.
Param | Type | Description |
---|---|---|
evt | string | RegExp |
Name of the event to attach the listener to. |
listener | function |
Method to be called when the event is triggered. If the function returns true, then it will be removed after calling. |
node.off(evt, listener)
Removes a listener function from the event on the node.
When passed a regular expression as the event name, it will remove the listener from all events that match it.
Param | Type | Description |
---|---|---|
evt | string | RegExp |
Name of the event to remove the listener from. |
listener | function |
Method to remove from the event. |
node.once(evt, listener)
Adds a listener function to the event on the node, this listener will automatically be removed after first execution.
If you pass a regular expression as the event name then the listener will be added to all events that match it.
Param | Type | Description |
---|---|---|
evt | string | RegExp |
Name of the event to attach the listener to. |
listener | function |
Method to be called when the event is triggered. |
node.trigger(evt)
Triggers an event of your choice.
When triggered, every listener attached to that event will be executed.
If you pass the optional arguments then those arguments will be passed to every listener upon execution.
Param | Type | Description |
---|---|---|
evt | string | RegExp |
Name of the event to emit and execute listeners for. |
[…args] | * |
Optional arguments to be passed to each listener. |
node.addPrefetch(prefetchNodeId) ⇒ Node
Adds a prefetch to a node.
Every node object contains a prefetch array, which consists of other node ids.
These ids are a hint to the player, that one of these prefetch nodes are likely to be pushed to the playlist following this node.
The player will use this hint in order to try and preload children once loading of this node completes.
If this node already contains the child prefetchNodeId, it will do nothing.
Returns: Node
- This node object.
See: removePrefetch
Param | Type | Description |
---|---|---|
prefetchNodeId | string |
Child node id. |
Example
var myNode = player.repository.get('myNode');
myNode.addPrefetch('childId');
node.removePrefetch(prefetchNodeId) ⇒ Node
Removes a prefetch from a node.
Returns: Node
- This node object.
See: addPrefetch
Param | Type | Description |
---|---|---|
prefetchNodeId | string |
Child node id. |
Example
var myNode = player.repository.get('myNode');
myNode.removePrefetch('noLongerChildId');
Events
“nodestart”
Triggered when node playback has started.
Param | Type | Description |
---|---|---|
node | Node |
Node object. |
index | number |
Node’s playlist index (0 based). |
“nodeend”
Triggered when node playback has completed.
Param | Type | Description |
---|---|---|
node | Node |
Node object. |
index | number |
Node’s playlist index (0 based). |
“nodecritical”
Triggered when node playback reached a critical point (nearing nodeend
event).
Unlike the playlistcritical event that’s triggered on the player, this event (which is triggered on the node instance)
is triggered regardless of whether or not a next node has been pushed to the playlist.
Param | Type | Description |
---|---|---|
node | Node |
Node object. |
index | number |
Node’s playlist index (0 based). |
“playlistpush”
Triggered when playlist.push() was called with this node.
See: playlist
Param | Type | Description |
---|---|---|
node | Node |
The node that was pushed to playlist (this node). |
index | number |
The node’s playlist index (0 based). |
“timeupdate”
This special event can be used to trigger a callback when node’s playback reaches a certain time (aka a cuepoint).
The timeupdate
event accepts a time argument (in seconds) in the event name (delimited by :
- see example).
When this time argument is a positive number, it refers to seconds from start of node.
A negative number refers to seconds before end of node.
Param | Type | Description |
---|---|---|
node | Node |
Node object. |
timeInNode | number |
Time in seconds from start of node. |
Example
var myNode = player.repository.get('myNode');
var callback = function(node, timeInNode) {
myNode.off('timeupdate:3.25', callback);
console.log('Playback time in ' + node.id + ' has reached ' + timeInNode + ' seconds!');
};
myNode.on('timeupdate:3.25', callback);