add worker paused and play events
diff --git a/player/js/animation/AnimationItem.js b/player/js/animation/AnimationItem.js
index 5a2cd33..9954110 100644
--- a/player/js/animation/AnimationItem.js
+++ b/player/js/animation/AnimationItem.js
@@ -57,6 +57,7 @@
this.configAnimation = this.configAnimation.bind(this);
this.onSetupError = this.onSetupError.bind(this);
this.onSegmentComplete = this.onSegmentComplete.bind(this);
+ this.drawnFrameEvent = new BMEnterFrameEvent('drawnFrame', 0, 0, 0);
};
extendPrototype([BaseEvent], AnimationItem);
@@ -385,6 +386,7 @@
}
if (this.isPaused === true) {
this.isPaused = false;
+ this.trigger('_pause');
this.audioController.resume();
if (this._idle) {
this._idle = false;
@@ -399,6 +401,7 @@
}
if (this.isPaused === false) {
this.isPaused = true;
+ this.trigger('_play');
this._idle = true;
this.trigger('_idle');
this.audioController.pause();
@@ -729,9 +732,14 @@
if (this._cbs && this._cbs[name]) {
switch (name) {
case 'enterFrame':
- case 'drawnFrame':
this.triggerEvent(name, new BMEnterFrameEvent(name, this.currentFrame, this.totalFrames, this.frameModifier));
break;
+ case 'drawnFrame':
+ this.drawnFrameEvent.currentTime = this.currentFrame;
+ this.drawnFrameEvent.totalTime = this.totalFrames;
+ this.drawnFrameEvent.direction = this.frameModifier;
+ this.triggerEvent(name, this.drawnFrameEvent);
+ break;
case 'loopComplete':
this.triggerEvent(name, new BMCompleteLoopEvent(name, this.loop, this.playCount, this.frameMult));
break;
diff --git a/player/js/worker_wrapper.js b/player/js/worker_wrapper.js
index 1e48bde..21cdbed 100644
--- a/player/js/worker_wrapper.js
+++ b/player/js/worker_wrapper.js
@@ -190,6 +190,22 @@
animation.onError = function (error) {
console.log('ERRORO', error); // eslint-disable-line
};
+ animation.addEventListener('_play', function () {
+ self.postMessage({
+ type: 'playing',
+ payload: {
+ id: payload.id,
+ },
+ });
+ });
+ animation.addEventListener('_pause', function () {
+ self.postMessage({
+ type: 'paused',
+ payload: {
+ id: payload.id,
+ },
+ });
+ });
if (params.renderer === 'svg') {
animation.addEventListener('DOMLoaded', function () {
var serialized = wrapper.serialize();
@@ -468,13 +484,31 @@
}
}
+ function handlePlaying(payload) {
+ var animation = animations[payload.id];
+ if (animation) {
+ animation.animInstance.isPaused = false;
+ }
+ }
+
+ function handlePaused(payload) {
+ var animation = animations[payload.id];
+ if (animation) {
+ animation.animInstance.isPaused = true;
+ }
+ }
+
+ var messageHandlers = {
+ loaded: handleAnimationLoaded,
+ updated: handleAnimationUpdate,
+ event: handleEvent,
+ playing: handlePlaying,
+ paused: handlePaused,
+ };
+
workerInstance.onmessage = function (event) {
- if (event.data.type === 'loaded') {
- handleAnimationLoaded(event.data.payload);
- } else if (event.data.type === 'updated') {
- handleAnimationUpdate(event.data.payload);
- } else if (event.data.type === 'event') {
- handleEvent(event.data.payload);
+ if (messageHandlers[event.data.type]) {
+ messageHandlers[event.data.type](event.data.payload);
}
};
@@ -518,6 +552,7 @@
};
var animInstance = {
id: animationId,
+ isPaused: true,
pause: function () {
workerInstance.postMessage({
type: 'pause',