timingsrc 1.2.7 → 1.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/es2019/factories/set-timingsrc-with-custom-update-function.d.ts.map +1 -1
- package/build/es2019/factories/set-timingsrc-with-custom-update-function.js +27 -9
- package/build/es2019/factories/set-timingsrc-with-custom-update-function.js.map +1 -1
- package/build/es5/bundle.js +69 -81
- package/package.json +11 -11
- package/src/factories/set-timingsrc-with-custom-update-function.ts +35 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"set-timingsrc-with-custom-update-function.d.ts","sourceRoot":"","sources":["../../../src/factories/set-timingsrc-with-custom-update-function.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAChF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,iCAAiC,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC9E,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAEvE,eAAO,MAAM,0CAA0C,mBACnC,uBAAuB,YAC7B,QAAQ,MACd,WAAW,sBACK,WAAW,+BAA+B,CAAC,uEAG7C,gBAAgB,gBAChB,aAAa,2FAED,IAAI,GAAG,iCAAiC,
|
|
1
|
+
{"version":3,"file":"set-timingsrc-with-custom-update-function.d.ts","sourceRoot":"","sources":["../../../src/factories/set-timingsrc-with-custom-update-function.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAChF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,iCAAiC,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC9E,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAEvE,eAAO,MAAM,0CAA0C,mBACnC,uBAAuB,YAC7B,QAAQ,MACd,WAAW,sBACK,WAAW,+BAA+B,CAAC,uEAG7C,gBAAgB,gBAChB,aAAa,2FAED,IAAI,GAAG,iCAAiC,eA8DzE,CAAC"}
|
|
@@ -8,16 +8,34 @@ export const createSetTimingsrcWithCustomUpdateFunction = (animationFrame, docum
|
|
|
8
8
|
const sanitizedDuration = typeof duration === 'number' && !isNaN(duration) ? duration : 0;
|
|
9
9
|
const { position, velocity } = previousUpdateVectorWithCustomState;
|
|
10
10
|
updateMediaElement(currentTime, sanitizedDuration, mediaElement, playbackRate, position, velocity);
|
|
11
|
+
return velocity !== 0;
|
|
11
12
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
let unsubscribe;
|
|
14
|
+
const updateOnce = () => {
|
|
15
|
+
if (!update()) {
|
|
16
|
+
unsubscribe();
|
|
17
|
+
unsubscribe = updateReactively();
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const updateConsistently = () => {
|
|
21
|
+
const unsubscribeFunctions = [
|
|
22
|
+
animationFrame()(() => updateOnce()),
|
|
23
|
+
on(timingObject, 'change')(() => {
|
|
24
|
+
if (document.visibilityState === 'hidden') {
|
|
25
|
+
updateOnce();
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
];
|
|
29
|
+
return () => unsubscribeFunctions.forEach((unsubscribeFunction) => unsubscribeFunction());
|
|
30
|
+
};
|
|
31
|
+
const updateReactively = () => on(timingObject, 'change')(() => {
|
|
32
|
+
if (update()) {
|
|
33
|
+
unsubscribe();
|
|
34
|
+
unsubscribe = updateConsistently();
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
unsubscribe = update() ? updateConsistently() : updateReactively();
|
|
38
|
+
return () => unsubscribe();
|
|
21
39
|
};
|
|
22
40
|
};
|
|
23
41
|
//# sourceMappingURL=set-timingsrc-with-custom-update-function.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"set-timingsrc-with-custom-update-function.js","sourceRoot":"","sources":["../../../src/factories/set-timingsrc-with-custom-update-function.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,MAAM,0CAA0C,GAAG,CACtD,cAAuC,EACvC,QAAkB,EAClB,EAAe,EACf,kBAA+D,EACjE,EAAE;IACA,OAAO,CACH,YAA8B,EAC9B,YAA2B,EAC3B,cAA4D,EAC5D,2BAAqE,IAAI,EAC3E,EAAE;QACA,IAAI,mCAAmC,GAAuC,IAAI,CAAC;QAEnF,MAAM,MAAM,GAAG,GAAG,EAAE;YAChB,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,GAAG,YAAY,CAAC;YAC7D,MAAM,iBAAiB,GAAG,YAAY,CAAC,KAAK,EAAE,CAAC;YAE/C,mCAAmC,GAAG,cAAc,CAChD,wBAAwB,KAAK,IAAI,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,wBAAwB,CAAC,iBAAiB,CAAC,EACnG,WAAW,EACX,mCAAmC,CACtC,CAAC;YAEF,MAAM,iBAAiB,GAAG,OAAO,QAAQ,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;YAC1F,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,mCAAmC,CAAC;YAEnE,kBAAkB,CAAC,WAAW,EAAE,iBAAiB,EAAE,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"set-timingsrc-with-custom-update-function.js","sourceRoot":"","sources":["../../../src/factories/set-timingsrc-with-custom-update-function.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,MAAM,0CAA0C,GAAG,CACtD,cAAuC,EACvC,QAAkB,EAClB,EAAe,EACf,kBAA+D,EACjE,EAAE;IACA,OAAO,CACH,YAA8B,EAC9B,YAA2B,EAC3B,cAA4D,EAC5D,2BAAqE,IAAI,EAC3E,EAAE;QACA,IAAI,mCAAmC,GAAuC,IAAI,CAAC;QAEnF,MAAM,MAAM,GAAG,GAAG,EAAE;YAChB,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,GAAG,YAAY,CAAC;YAC7D,MAAM,iBAAiB,GAAG,YAAY,CAAC,KAAK,EAAE,CAAC;YAE/C,mCAAmC,GAAG,cAAc,CAChD,wBAAwB,KAAK,IAAI,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,wBAAwB,CAAC,iBAAiB,CAAC,EACnG,WAAW,EACX,mCAAmC,CACtC,CAAC;YAEF,MAAM,iBAAiB,GAAG,OAAO,QAAQ,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;YAC1F,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,mCAAmC,CAAC;YAEnE,kBAAkB,CAAC,WAAW,EAAE,iBAAiB,EAAE,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;YAEnG,OAAO,QAAQ,KAAK,CAAC,CAAC;QAC1B,CAAC,CAAC;QAEF,IAAI,WAAuB,CAAC;QAE5B,MAAM,UAAU,GAAG,GAAG,EAAE;YACpB,IAAI,CAAC,MAAM,EAAE,EAAE;gBACX,WAAW,EAAE,CAAC;gBAEd,WAAW,GAAG,gBAAgB,EAAE,CAAC;aACpC;QACL,CAAC,CAAC;QACF,MAAM,kBAAkB,GAAG,GAAG,EAAE;YAC5B,MAAM,oBAAoB,GAAG;gBACzB,cAAc,EAAE,CAAC,GAAG,EAAE,CAAC,UAAU,EAAE,CAAC;gBACpC,EAAE,CACE,YAAY,EACZ,QAAQ,CACX,CAAC,GAAG,EAAE;oBACH,IAAI,QAAQ,CAAC,eAAe,KAAK,QAAQ,EAAE;wBACvC,UAAU,EAAE,CAAC;qBAChB;gBACL,CAAC,CAAC;aACL,CAAC;YAEF,OAAO,GAAG,EAAE,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC,mBAAmB,EAAE,EAAE,CAAC,mBAAmB,EAAE,CAAC,CAAC;QAC9F,CAAC,CAAC;QACF,MAAM,gBAAgB,GAAG,GAAG,EAAE,CAC1B,EAAE,CACE,YAAY,EACZ,QAAQ,CACX,CAAC,GAAG,EAAE;YACH,IAAI,MAAM,EAAE,EAAE;gBACV,WAAW,EAAE,CAAC;gBAEd,WAAW,GAAG,kBAAkB,EAAE,CAAC;aACtC;QACL,CAAC,CAAC,CAAC;QAEP,WAAW,GAAG,MAAM,EAAE,CAAC,CAAC,CAAC,kBAAkB,EAAE,CAAC,CAAC,CAAC,gBAAgB,EAAE,CAAC;QAEnE,OAAO,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC;IAC/B,CAAC,CAAC;AACN,CAAC,CAAC"}
|
package/build/es5/bundle.js
CHANGED
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
var createSetCurrentTime = function createSetCurrentTime(currentTimeAssignments) {
|
|
26
26
|
return function (mediaElement, previousValue, nextValue) {
|
|
27
27
|
var currentTimeAssignment = currentTimeAssignments.get(mediaElement);
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
if (currentTimeAssignment === undefined ||
|
|
29
|
+
// Bug #5: Safari limits the precision of the value after a while.
|
|
30
30
|
Math.abs(currentTimeAssignment[0] - previousValue) > 0.0001 || currentTimeAssignment[1] !== nextValue) {
|
|
31
31
|
mediaElement.currentTime = nextValue;
|
|
32
32
|
currentTimeAssignments.set(mediaElement, [mediaElement.currentTime, nextValue]);
|
|
@@ -37,7 +37,6 @@
|
|
|
37
37
|
var createSetPlaybackRate = function createSetPlaybackRate(playbackRateAssignments) {
|
|
38
38
|
return function (mediaElement, previousValue, nextValue) {
|
|
39
39
|
var playbackRateAssignment = playbackRateAssignments.get(mediaElement);
|
|
40
|
-
|
|
41
40
|
if (playbackRateAssignment === undefined || playbackRateAssignment[0] !== previousValue || playbackRateAssignment[1] !== nextValue) {
|
|
42
41
|
// There is currently a bug in Firefox which causes problems when switching back to a playbackRate of exactly 1.
|
|
43
42
|
mediaElement.playbackRate = nextValue === 1 ? previousValue > 1 ? 1.00001 : 0.99999 : nextValue;
|
|
@@ -57,49 +56,66 @@
|
|
|
57
56
|
return function (mediaElement, timingObject, updateFunction) {
|
|
58
57
|
var prepareTimingStateVector = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
|
|
59
58
|
var previousUpdateVectorWithCustomState = null;
|
|
60
|
-
|
|
61
59
|
var update = function update() {
|
|
62
60
|
var currentTime = mediaElement.currentTime,
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
duration = mediaElement.duration,
|
|
62
|
+
playbackRate = mediaElement.playbackRate;
|
|
65
63
|
var timingStateVector = timingObject.query();
|
|
66
64
|
previousUpdateVectorWithCustomState = updateFunction(prepareTimingStateVector === null ? timingStateVector : prepareTimingStateVector(timingStateVector), currentTime, previousUpdateVectorWithCustomState);
|
|
67
65
|
var sanitizedDuration = typeof duration === 'number' && !isNaN(duration) ? duration : 0;
|
|
68
66
|
var _previousUpdateVector = previousUpdateVectorWithCustomState,
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
position = _previousUpdateVector.position,
|
|
68
|
+
velocity = _previousUpdateVector.velocity;
|
|
71
69
|
updateMediaElement(currentTime, sanitizedDuration, mediaElement, playbackRate, position, velocity);
|
|
70
|
+
return velocity !== 0;
|
|
72
71
|
};
|
|
73
|
-
|
|
74
|
-
var
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
update();
|
|
72
|
+
var unsubscribe;
|
|
73
|
+
var updateOnce = function updateOnce() {
|
|
74
|
+
if (!update()) {
|
|
75
|
+
unsubscribe();
|
|
76
|
+
unsubscribe = updateReactively();
|
|
79
77
|
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
return
|
|
78
|
+
};
|
|
79
|
+
var updateConsistently = function updateConsistently() {
|
|
80
|
+
var unsubscribeFunctions = [animationFrame()(function () {
|
|
81
|
+
return updateOnce();
|
|
82
|
+
}), on(timingObject, 'change')(function () {
|
|
83
|
+
if (document.visibilityState === 'hidden') {
|
|
84
|
+
updateOnce();
|
|
85
|
+
}
|
|
86
|
+
})];
|
|
87
|
+
return function () {
|
|
88
|
+
return unsubscribeFunctions.forEach(function (unsubscribeFunction) {
|
|
89
|
+
return unsubscribeFunction();
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
var updateReactively = function updateReactively() {
|
|
94
|
+
return on(timingObject, 'change')(function () {
|
|
95
|
+
if (update()) {
|
|
96
|
+
unsubscribe();
|
|
97
|
+
unsubscribe = updateConsistently();
|
|
98
|
+
}
|
|
84
99
|
});
|
|
85
100
|
};
|
|
101
|
+
unsubscribe = update() ? updateConsistently() : updateReactively();
|
|
102
|
+
return function () {
|
|
103
|
+
return unsubscribe();
|
|
104
|
+
};
|
|
86
105
|
};
|
|
87
106
|
};
|
|
88
107
|
|
|
89
108
|
var createUpdateGradually = function createUpdateGradually(computeVelocity, _ref, threshold, tolerance, updateVectorWithNewPosition) {
|
|
90
109
|
var _ref2 = _slicedToArray__default["default"](_ref, 2),
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
110
|
+
minValue = _ref2[0],
|
|
111
|
+
maxValue = _ref2[1];
|
|
94
112
|
return function (_ref3, currentTime, previousUpdateVectorWithCustomState) {
|
|
95
113
|
var position = _ref3.position,
|
|
96
|
-
|
|
97
|
-
|
|
114
|
+
velocity = _ref3.velocity;
|
|
98
115
|
var _ref4 = previousUpdateVectorWithCustomState !== null && previousUpdateVectorWithCustomState !== void 0 ? previousUpdateVectorWithCustomState : {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
116
|
+
mediaElementDelay: 0
|
|
117
|
+
},
|
|
118
|
+
mediaElementDelay = _ref4.mediaElementDelay;
|
|
103
119
|
if (velocity < minValue || velocity > maxValue) {
|
|
104
120
|
return {
|
|
105
121
|
mediaElementDelay: mediaElementDelay,
|
|
@@ -107,7 +123,6 @@
|
|
|
107
123
|
velocity: 0
|
|
108
124
|
};
|
|
109
125
|
}
|
|
110
|
-
|
|
111
126
|
if (position < 0 || velocity === 0) {
|
|
112
127
|
return {
|
|
113
128
|
mediaElementDelay: mediaElementDelay,
|
|
@@ -115,33 +130,27 @@
|
|
|
115
130
|
velocity: velocity
|
|
116
131
|
};
|
|
117
132
|
}
|
|
118
|
-
|
|
119
133
|
var positionDifference = currentTime - position;
|
|
120
134
|
var absolutePositionDifference = Math.abs(positionDifference);
|
|
121
|
-
|
|
122
135
|
if (absolutePositionDifference > threshold) {
|
|
123
136
|
var _ref5 = previousUpdateVectorWithCustomState !== null && previousUpdateVectorWithCustomState !== void 0 ? previousUpdateVectorWithCustomState : {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
137
|
+
position: null
|
|
138
|
+
},
|
|
139
|
+
lastPosition = _ref5.position;
|
|
128
140
|
if (positionDifference < 0 || positionDifference > mediaElementDelay) {
|
|
129
141
|
if (lastPosition === currentTime) {
|
|
130
142
|
mediaElementDelay += absolutePositionDifference;
|
|
131
143
|
}
|
|
132
|
-
|
|
133
144
|
return updateVectorWithNewPosition(mediaElementDelay, position, function (nextPosition) {
|
|
134
145
|
return computeVelocity(nextPosition - position, minValue, maxValue, velocity);
|
|
135
146
|
});
|
|
136
147
|
}
|
|
137
|
-
|
|
138
148
|
if (lastPosition !== currentTime) {
|
|
139
149
|
return updateVectorWithNewPosition(mediaElementDelay - absolutePositionDifference, position, function (nextPosition) {
|
|
140
150
|
return computeVelocity(nextPosition - position, minValue, maxValue, velocity);
|
|
141
151
|
});
|
|
142
152
|
}
|
|
143
153
|
}
|
|
144
|
-
|
|
145
154
|
if (absolutePositionDifference > tolerance) {
|
|
146
155
|
return {
|
|
147
156
|
mediaElementDelay: mediaElementDelay,
|
|
@@ -149,7 +158,6 @@
|
|
|
149
158
|
velocity: computeVelocity(positionDifference, minValue, maxValue, velocity)
|
|
150
159
|
};
|
|
151
160
|
}
|
|
152
|
-
|
|
153
161
|
return {
|
|
154
162
|
mediaElementDelay: mediaElementDelay,
|
|
155
163
|
position: currentTime,
|
|
@@ -164,22 +172,18 @@
|
|
|
164
172
|
if (currentTime > 0) {
|
|
165
173
|
setCurrentTime(mediaElement, currentTime, 0);
|
|
166
174
|
}
|
|
167
|
-
|
|
168
175
|
pause(mediaElement);
|
|
169
176
|
} else if (position >= duration) {
|
|
170
177
|
if (currentTime !== duration) {
|
|
171
178
|
setCurrentTime(mediaElement, currentTime, duration);
|
|
172
179
|
}
|
|
173
|
-
|
|
174
180
|
pause(mediaElement);
|
|
175
181
|
} else if (currentTime !== position) {
|
|
176
182
|
setCurrentTime(mediaElement, currentTime, position);
|
|
177
|
-
|
|
178
183
|
if (velocity !== 0) {
|
|
179
184
|
if (playbackRate !== velocity) {
|
|
180
185
|
setPlaybackRate(mediaElement, playbackRate, velocity);
|
|
181
186
|
}
|
|
182
|
-
|
|
183
187
|
play(mediaElement);
|
|
184
188
|
} else {
|
|
185
189
|
pause(mediaElement);
|
|
@@ -200,22 +204,21 @@
|
|
|
200
204
|
return function (tolerance) {
|
|
201
205
|
return function (timingStateVector, currentTime, previousUpdateVectorWithCustomState) {
|
|
202
206
|
var _ref = previousUpdateVectorWithCustomState !== null && previousUpdateVectorWithCustomState !== void 0 ? previousUpdateVectorWithCustomState : {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
207
|
+
lastAppliedPostion: 0,
|
|
208
|
+
lastAppliedTimestamp: 0,
|
|
209
|
+
lastAppliedVelocity: 0,
|
|
210
|
+
lastPlayheadDifference: 0,
|
|
211
|
+
mediaElementDelay: 0,
|
|
212
|
+
numberOfDetectedResets: 0,
|
|
213
|
+
numberOfExpectedResets: 1
|
|
214
|
+
},
|
|
215
|
+
lastAppliedPostion = _ref.lastAppliedPostion,
|
|
216
|
+
lastAppliedTimestamp = _ref.lastAppliedTimestamp,
|
|
217
|
+
lastAppliedVelocity = _ref.lastAppliedVelocity,
|
|
218
|
+
lastPlayheadDifference = _ref.lastPlayheadDifference,
|
|
219
|
+
mediaElementDelay = _ref.mediaElementDelay,
|
|
220
|
+
numberOfDetectedResets = _ref.numberOfDetectedResets,
|
|
221
|
+
numberOfExpectedResets = _ref.numberOfExpectedResets;
|
|
219
222
|
if (timingStateVector.position < 0 || timingStateVector.velocity === 0) {
|
|
220
223
|
lastAppliedPostion = timingStateVector.position;
|
|
221
224
|
lastAppliedVelocity = timingStateVector.velocity;
|
|
@@ -230,16 +233,13 @@
|
|
|
230
233
|
position: lastAppliedPostion,
|
|
231
234
|
velocity: lastAppliedVelocity
|
|
232
235
|
};
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
+
}
|
|
237
|
+
// Bug #4: Safari decreases currentTime after playing for about 200 milliseconds.
|
|
236
238
|
if (lastAppliedVelocity === timingStateVector.velocity && lastPlayheadDifference < MAXIMUM_PLAYHEAD_DIFFERENCE) {
|
|
237
239
|
var playheadDifference = Math.abs(currentTime - lastAppliedPostion) * lastAppliedVelocity;
|
|
238
|
-
|
|
239
240
|
if (playheadDifference < MAXIMUM_PLAYHEAD_DIFFERENCE) {
|
|
240
241
|
if (playheadDifference + 0.001 > lastPlayheadDifference) {
|
|
241
242
|
lastPlayheadDifference = playheadDifference;
|
|
242
|
-
|
|
243
243
|
if (numberOfDetectedResets < numberOfExpectedResets) {
|
|
244
244
|
return {
|
|
245
245
|
lastAppliedPostion: lastAppliedPostion,
|
|
@@ -256,7 +256,6 @@
|
|
|
256
256
|
} else {
|
|
257
257
|
lastPlayheadDifference = playheadDifference;
|
|
258
258
|
numberOfDetectedResets += 1;
|
|
259
|
-
|
|
260
259
|
if (numberOfDetectedResets <= numberOfExpectedResets) {
|
|
261
260
|
return {
|
|
262
261
|
lastAppliedPostion: lastAppliedPostion,
|
|
@@ -270,7 +269,6 @@
|
|
|
270
269
|
velocity: lastAppliedVelocity
|
|
271
270
|
};
|
|
272
271
|
}
|
|
273
|
-
|
|
274
272
|
numberOfExpectedResets += 1;
|
|
275
273
|
}
|
|
276
274
|
} else {
|
|
@@ -280,25 +278,20 @@
|
|
|
280
278
|
} else {
|
|
281
279
|
lastAppliedTimestamp = 0;
|
|
282
280
|
}
|
|
283
|
-
|
|
284
281
|
var positionDifference = Math.abs(currentTime - timingStateVector.position);
|
|
285
282
|
var velocityHasChanged = lastAppliedVelocity === 0 || lastAppliedVelocity < 0 && timingStateVector.velocity > 0 || lastAppliedVelocity > 0 && timingStateVector.velocity < 0;
|
|
286
|
-
|
|
287
283
|
if (positionDifference > tolerance || velocityHasChanged) {
|
|
288
284
|
if (lastAppliedTimestamp > 0) {
|
|
289
285
|
var elapsedTime = timingStateVector.timestamp - lastAppliedTimestamp;
|
|
290
|
-
|
|
291
286
|
var _translateTimingState = translateTimingStateVector({
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
287
|
+
acceleration: 0,
|
|
288
|
+
position: lastAppliedPostion,
|
|
289
|
+
timestamp: lastAppliedTimestamp,
|
|
290
|
+
velocity: lastAppliedVelocity
|
|
291
|
+
}, elapsedTime),
|
|
292
|
+
position = _translateTimingState.position;
|
|
299
293
|
mediaElementDelay = position - currentTime;
|
|
300
294
|
}
|
|
301
|
-
|
|
302
295
|
lastAppliedPostion = timingStateVector.position + mediaElementDelay;
|
|
303
296
|
lastAppliedVelocity = timingStateVector.velocity;
|
|
304
297
|
return {
|
|
@@ -313,7 +306,6 @@
|
|
|
313
306
|
velocity: lastAppliedVelocity
|
|
314
307
|
};
|
|
315
308
|
}
|
|
316
|
-
|
|
317
309
|
return {
|
|
318
310
|
lastAppliedPostion: lastAppliedPostion,
|
|
319
311
|
lastAppliedTimestamp: lastAppliedTimestamp,
|
|
@@ -338,9 +330,7 @@
|
|
|
338
330
|
if (window === null) {
|
|
339
331
|
return DEFAULT_VALUES;
|
|
340
332
|
}
|
|
341
|
-
|
|
342
333
|
var audio = new window.Audio();
|
|
343
|
-
|
|
344
334
|
try {
|
|
345
335
|
// Bug #2: Chrome does not support values above 16.
|
|
346
336
|
audio.playbackRate = 17;
|
|
@@ -348,14 +338,12 @@
|
|
|
348
338
|
// Bug #1: Chrome does not support values below 0.625.
|
|
349
339
|
return [0.625, 16];
|
|
350
340
|
}
|
|
351
|
-
|
|
352
341
|
try {
|
|
353
342
|
// Bug #3: Firefox does not support negative values.
|
|
354
343
|
audio.playbackRate = -1;
|
|
355
344
|
} catch (_unused2) {
|
|
356
345
|
return [0, DEFAULT_VALUES[1]];
|
|
357
346
|
}
|
|
358
|
-
|
|
359
347
|
return DEFAULT_VALUES;
|
|
360
348
|
};
|
|
361
349
|
|
package/package.json
CHANGED
|
@@ -9,24 +9,24 @@
|
|
|
9
9
|
}
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@babel/runtime": "^7.19.
|
|
13
|
-
"subscribable-things": "^2.1.
|
|
14
|
-
"timing-object": "^3.1.
|
|
12
|
+
"@babel/runtime": "^7.19.4",
|
|
13
|
+
"subscribable-things": "^2.1.8",
|
|
14
|
+
"timing-object": "^3.1.49",
|
|
15
15
|
"tslib": "^2.4.0"
|
|
16
16
|
},
|
|
17
17
|
"description": "A library to synchronize a MediaElement with a TimingObject.",
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@babel/core": "^7.19.
|
|
19
|
+
"@babel/core": "^7.19.6",
|
|
20
20
|
"@babel/plugin-external-helpers": "^7.18.6",
|
|
21
|
-
"@babel/plugin-transform-runtime": "^7.19.
|
|
22
|
-
"@babel/preset-env": "^7.19.
|
|
21
|
+
"@babel/plugin-transform-runtime": "^7.19.6",
|
|
22
|
+
"@babel/preset-env": "^7.19.4",
|
|
23
23
|
"@commitlint/cli": "^17.1.2",
|
|
24
24
|
"@commitlint/config-angular": "^17.1.0",
|
|
25
25
|
"@rollup/plugin-babel": "^5.3.1",
|
|
26
26
|
"chai": "^4.3.6",
|
|
27
27
|
"commitizen": "^4.2.5",
|
|
28
28
|
"cz-conventional-changelog": "^3.3.0",
|
|
29
|
-
"eslint": "^8.
|
|
29
|
+
"eslint": "^8.26.0",
|
|
30
30
|
"eslint-config-holy-grail": "^52.0.33",
|
|
31
31
|
"grunt": "^1.5.3",
|
|
32
32
|
"grunt-cli": "^1.4.3",
|
|
@@ -41,18 +41,18 @@
|
|
|
41
41
|
"karma-sinon-chai": "^2.0.2",
|
|
42
42
|
"karma-webpack": "^5.0.0",
|
|
43
43
|
"load-grunt-config": "^4.0.1",
|
|
44
|
-
"mocha": "^10.
|
|
44
|
+
"mocha": "^10.1.0",
|
|
45
45
|
"prettier": "^2.7.1",
|
|
46
46
|
"pretty-quick": "^3.1.3",
|
|
47
47
|
"rimraf": "^3.0.2",
|
|
48
48
|
"rollup": "^2.79.1",
|
|
49
|
-
"sinon": "^14.0.
|
|
49
|
+
"sinon": "^14.0.1",
|
|
50
50
|
"sinon-chai": "^3.7.0",
|
|
51
51
|
"ts-loader": "^9.4.1",
|
|
52
52
|
"tsconfig-holy-grail": "^11.1.36",
|
|
53
53
|
"tslint": "^6.1.3",
|
|
54
54
|
"tslint-config-holy-grail": "^53.2.33",
|
|
55
|
-
"typescript": "^4.8.
|
|
55
|
+
"typescript": "^4.8.4",
|
|
56
56
|
"webpack": "^5.74.0"
|
|
57
57
|
},
|
|
58
58
|
"files": [
|
|
@@ -75,5 +75,5 @@
|
|
|
75
75
|
"test": "grunt lint && grunt test"
|
|
76
76
|
},
|
|
77
77
|
"types": "build/es2019/module.d.ts",
|
|
78
|
-
"version": "1.2.
|
|
78
|
+
"version": "1.2.9"
|
|
79
79
|
}
|
|
@@ -32,20 +32,48 @@ export const createSetTimingsrcWithCustomUpdateFunction = (
|
|
|
32
32
|
const { position, velocity } = previousUpdateVectorWithCustomState;
|
|
33
33
|
|
|
34
34
|
updateMediaElement(currentTime, sanitizedDuration, mediaElement, playbackRate, position, velocity);
|
|
35
|
+
|
|
36
|
+
return velocity !== 0;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
let unsubscribe: () => void;
|
|
40
|
+
|
|
41
|
+
const updateOnce = () => {
|
|
42
|
+
if (!update()) {
|
|
43
|
+
unsubscribe();
|
|
44
|
+
|
|
45
|
+
unsubscribe = updateReactively();
|
|
46
|
+
}
|
|
35
47
|
};
|
|
48
|
+
const updateConsistently = () => {
|
|
49
|
+
const unsubscribeFunctions = [
|
|
50
|
+
animationFrame()(() => updateOnce()),
|
|
51
|
+
on(
|
|
52
|
+
timingObject,
|
|
53
|
+
'change'
|
|
54
|
+
)(() => {
|
|
55
|
+
if (document.visibilityState === 'hidden') {
|
|
56
|
+
updateOnce();
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
];
|
|
36
60
|
|
|
37
|
-
|
|
38
|
-
|
|
61
|
+
return () => unsubscribeFunctions.forEach((unsubscribeFunction) => unsubscribeFunction());
|
|
62
|
+
};
|
|
63
|
+
const updateReactively = () =>
|
|
39
64
|
on(
|
|
40
65
|
timingObject,
|
|
41
66
|
'change'
|
|
42
67
|
)(() => {
|
|
43
|
-
if (
|
|
44
|
-
|
|
68
|
+
if (update()) {
|
|
69
|
+
unsubscribe();
|
|
70
|
+
|
|
71
|
+
unsubscribe = updateConsistently();
|
|
45
72
|
}
|
|
46
|
-
})
|
|
47
|
-
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
unsubscribe = update() ? updateConsistently() : updateReactively();
|
|
48
76
|
|
|
49
|
-
return () =>
|
|
77
|
+
return () => unsubscribe();
|
|
50
78
|
};
|
|
51
79
|
};
|