diff --git a/renderers-clocks.ts b/renderers-clocks.ts index ab8add0..fab0159 100644 --- a/renderers-clocks.ts +++ b/renderers-clocks.ts @@ -102,7 +102,7 @@ module libjass.renderers { toggle(): void; /** - * Enable or disable the renderer. + * Enable or disable the clock. * * @param {boolean} enabled If true, the clock is enabled, otherwise it's disabled. * @return {boolean} True if the clock is now in the given state, false if it was already in that state. @@ -261,9 +261,7 @@ module libjass.renderers { this._enabled = true; - if (this._nextAnimationFrameRequestId === null) { - this._nextAnimationFrameRequestId = requestAnimationFrame(() => this._onTimerTick()); - } + this._startTicking(); return true; } @@ -287,10 +285,7 @@ module libjass.renderers { this._dispatchEvent(ClockEvent.Stop, []); - if (this._nextAnimationFrameRequestId !== null) { - cancelAnimationFrame(this._nextAnimationFrameRequestId); - this._nextAnimationFrameRequestId = null; - } + this._stopTicking(); return true; } @@ -331,9 +326,7 @@ module libjass.renderers { return; } - if (this._nextAnimationFrameRequestId === null) { - this._nextAnimationFrameRequestId = requestAnimationFrame(() => this._onTimerTick()); - } + this._startTicking(); } private _onVideoPause(): void { @@ -357,12 +350,7 @@ module libjass.renderers { return; } - cancelAnimationFrame(this._nextAnimationFrameRequestId); - this._nextAnimationFrameRequestId = null; - - if (libjass.verboseMode) { - console.log("VideoClock._onVideoPause: Cancelled VideoClock._nextAnimationFrameRequestId"); - } + this._stopTicking(); } private _onVideoSeeking(): void { @@ -411,6 +399,19 @@ module libjass.renderers { this._nextAnimationFrameRequestId = requestAnimationFrame(() => this._onTimerTick()); } + private _startTicking(): void { + if (this._nextAnimationFrameRequestId === null) { + this._nextAnimationFrameRequestId = requestAnimationFrame(() => this._onTimerTick()); + } + } + + private _stopTicking(): void { + if (this._nextAnimationFrameRequestId !== null) { + cancelAnimationFrame(this._nextAnimationFrameRequestId); + this._nextAnimationFrameRequestId = null; + } + } + // EventSource members _eventListeners: Map = new Map(); addEventListener: (type: ClockEvent, listener: Function) => void; diff --git a/renderers-null.ts b/renderers-null.ts index 2e0776c..7677f77 100644 --- a/renderers-null.ts +++ b/renderers-null.ts @@ -145,7 +145,7 @@ module libjass.renderers { * Runs when the clock's current time changed. This might be a result of either regular playback or seeking. */ _onClockTick(): void { - var currentTime = this.clock.currentTime; + var currentTime = this._clock.currentTime; if (libjass.verboseMode) { console.log("NullRenderer._onClockTick: currentTime = " + currentTime);