-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
65 lines (48 loc) · 1.28 KB
/
index.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import videojs from 'video.js';
const createNewRanges = (timeRanges, playbackRate) => {
const newRanges = [];
for (let i = 0; i < timeRanges.length; i++) {
newRanges.push([
timeRanges.start(i) / playbackRate,
timeRanges.end(i) / playbackRate]);
}
return videojs.createTimeRange(newRanges);
};
const playbackrateAdjuster = function(player) {
let tech;
player.on('ratechange', function() {
tech.trigger('durationchange');
tech.trigger('timeupdate');
});
return {
setSource(srcObj, next) {
next(null, srcObj);
},
setTech(newTech) {
tech = newTech;
},
duration(dur) {
return dur / player.playbackRate();
},
currentTime(ct) {
return ct / player.playbackRate();
},
setCurrentTime(ct) {
return ct * player.playbackRate();
},
buffered(bf) {
return createNewRanges(bf, player.playbackRate());
},
seekable(seekable) {
return createNewRanges(seekable, player.playbackRate());
},
played(played) {
return createNewRanges(played, player.playbackRate());
}
};
};
// Register the plugin with video.js.
videojs.use('*', playbackrateAdjuster);
// Include the version number.
playbackrateAdjuster.VERSION = '__VERSION__';
export default playbackrateAdjuster;