Skip to content

Commit 744a892

Browse files
committed
playClip works better when timer fires slowly
1 parent 925a3dd commit 744a892

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/stackTools/playClip.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ function playClip(element, framesPerSecond) {
139139
playClipData = {
140140
intervalId: undefined,
141141
framesPerSecond: 30,
142-
lastFrameTimeStamp: undefined,
142+
lastFrameTimeStamp: new Date().getTime(),
143143
frameRate: 0,
144144
frameTimeVector: undefined,
145145
ignoreFrameTimeVector: false,
@@ -182,15 +182,19 @@ function playClip(element, framesPerSecond) {
182182
startLoadingHandler,
183183
endLoadingHandler,
184184
errorLoadingHandler,
185+
newlastFrameTimeStamp = new Date().getTime(),
186+
deltatime = newlastFrameTimeStamp - playClipData.lastFrameTimeStamp,
187+
frames = Math.round((playClipData.framesPerSecond / 1000) * deltatime),
185188
newImageIdIndex = stackData.currentImageIdIndex;
186189

187190
const imageCount = stackData.imageIds.length;
188191

189192
if (playClipData.reverse) {
190-
newImageIdIndex--;
193+
newImageIdIndex -= frames;
191194
} else {
192-
newImageIdIndex++;
195+
newImageIdIndex += frames;
193196
}
197+
playClipData.lastFrameTimeStamp = newlastFrameTimeStamp;
194198

195199
if (
196200
!playClipData.loop &&

0 commit comments

Comments
 (0)