-
Notifications
You must be signed in to change notification settings - Fork 416
/
middleware-set-current-time.js
35 lines (31 loc) · 1.19 KB
/
middleware-set-current-time.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import videojs from 'video.js';
// since VHS handles HLS and DASH (and in the future, more types), use * to capture all
videojs.use('*', (player) => {
return {
setSource(srcObj, next) {
// pass null as the first argument to indicate that the source is not rejected
next(null, srcObj);
},
// VHS needs to know when seeks happen. For external seeks (generated at the player
// level), this middleware will capture the action. For internal seeks (generated at
// the tech level), we use a wrapped function so that we can handle it on our own
// (specified elsewhere).
setCurrentTime(time) {
if (player.vhs &&
player.currentSource().src === player.vhs.source_.src) {
player.vhs.setCurrentTime(time);
}
return time;
},
// Sync VHS after play requests.
// This specifically handles replay where the order of actions is
// play, video element will seek to 0 (skipping the setCurrentTime middleware)
// then triggers a play event.
play() {
if (player.vhs &&
player.currentSource().src === player.vhs.source_.src) {
player.vhs.setCurrentTime(player.tech_.currentTime());
}
}
};
});