@checksub_team/peaks_timeline 1.4.53 → 1.5.0
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/package.json +1 -1
- package/peaks.js +6 -110
- package/src/player.js +12 -118
- package/src/playhead-layer.js +0 -81
- package/src/timeline-zoomview.js +0 -2
package/package.json
CHANGED
package/peaks.js
CHANGED
|
@@ -15983,51 +15983,7 @@ module.exports = function (Utils) {
|
|
|
15983
15983
|
var self = this;
|
|
15984
15984
|
self._peaks = peaks;
|
|
15985
15985
|
self._currentTime = 0;
|
|
15986
|
-
self._isPlaying = false;
|
|
15987
|
-
self._speed = 1;
|
|
15988
|
-
self._segmentPlayInterval = null;
|
|
15989
15986
|
}
|
|
15990
|
-
Player.prototype.setSpeed = function (newSpeed) {
|
|
15991
|
-
this._speed = newSpeed;
|
|
15992
|
-
};
|
|
15993
|
-
Player.prototype.destroy = function () {
|
|
15994
|
-
if (this._segmentPlayInterval !== null) {
|
|
15995
|
-
clearInterval(this._segmentPlayInterval);
|
|
15996
|
-
this._segmentPlayInterval = null;
|
|
15997
|
-
}
|
|
15998
|
-
if (this._playInterval !== null) {
|
|
15999
|
-
clearInterval(this._playInterval);
|
|
16000
|
-
this._playInterval = null;
|
|
16001
|
-
}
|
|
16002
|
-
};
|
|
16003
|
-
Player.prototype.play = function () {
|
|
16004
|
-
if (!this._playInterval) {
|
|
16005
|
-
var prevTime = performance.now();
|
|
16006
|
-
var time;
|
|
16007
|
-
var self = this;
|
|
16008
|
-
this._isPlaying = true;
|
|
16009
|
-
this._peaks.overrideInteractions(true, false);
|
|
16010
|
-
this._playInterval = setInterval(function () {
|
|
16011
|
-
time = performance.now();
|
|
16012
|
-
self._currentTime += (time - prevTime) / 1000 * self._speed;
|
|
16013
|
-
prevTime = time;
|
|
16014
|
-
self._peaks.emit('timeline.update', self._currentTime);
|
|
16015
|
-
}, 20);
|
|
16016
|
-
this._peaks.emit('timeline.play', this._currentTime);
|
|
16017
|
-
}
|
|
16018
|
-
};
|
|
16019
|
-
Player.prototype.pause = function () {
|
|
16020
|
-
if (this._playInterval) {
|
|
16021
|
-
this._isPlaying = false;
|
|
16022
|
-
clearInterval(this._playInterval);
|
|
16023
|
-
this._playInterval = null;
|
|
16024
|
-
this._peaks.overrideInteractions(false);
|
|
16025
|
-
this._peaks.emit('timeline.pause', this._currentTime);
|
|
16026
|
-
}
|
|
16027
|
-
};
|
|
16028
|
-
Player.prototype.isPlaying = function () {
|
|
16029
|
-
return this._isPlaying;
|
|
16030
|
-
};
|
|
16031
15987
|
Player.prototype.getCurrentTime = function () {
|
|
16032
15988
|
return this._currentTime;
|
|
16033
15989
|
};
|
|
@@ -16037,6 +15993,12 @@ module.exports = function (Utils) {
|
|
|
16037
15993
|
}
|
|
16038
15994
|
this._peaks.emit('timeline.seek', this._currentTime);
|
|
16039
15995
|
};
|
|
15996
|
+
Player.prototype.update = function (time) {
|
|
15997
|
+
if (!this._seek(time)) {
|
|
15998
|
+
return;
|
|
15999
|
+
}
|
|
16000
|
+
this._peaks.emit('timeline.update', this._currentTime);
|
|
16001
|
+
};
|
|
16040
16002
|
Player.prototype._seek = function (time) {
|
|
16041
16003
|
if (!Utils.isValidTime(time)) {
|
|
16042
16004
|
this._peaks.logger('peaks.player.seek(): parameter must be a valid time, in seconds');
|
|
@@ -16045,24 +16007,6 @@ module.exports = function (Utils) {
|
|
|
16045
16007
|
this._currentTime = Math.max(0, time);
|
|
16046
16008
|
return true;
|
|
16047
16009
|
};
|
|
16048
|
-
Player.prototype.playSegment = function (segment) {
|
|
16049
|
-
var self = this;
|
|
16050
|
-
if (!segment || !Utils.isValidTime(segment.startTime) || !Utils.isValidTime(segment.endTime)) {
|
|
16051
|
-
self._peaks.logger('peaks.player.playSegment(): parameter must be a segment object');
|
|
16052
|
-
return;
|
|
16053
|
-
}
|
|
16054
|
-
clearInterval(self._segmentPlayInterval);
|
|
16055
|
-
self._segmentPlayInterval = null;
|
|
16056
|
-
self.seek(segment.startTime);
|
|
16057
|
-
self.play();
|
|
16058
|
-
self._segmentPlayInterval = setInterval(function () {
|
|
16059
|
-
if (self.getCurrentTime() >= segment.endTime || !self._isPlaying) {
|
|
16060
|
-
clearInterval(self._segmentPlayInterval);
|
|
16061
|
-
self._segmentPlayInterval = null;
|
|
16062
|
-
self.pause();
|
|
16063
|
-
}
|
|
16064
|
-
}, 10);
|
|
16065
|
-
};
|
|
16066
16010
|
return Player;
|
|
16067
16011
|
}(_dereq_('./utils'));
|
|
16068
16012
|
},{"./utils":111}],99:[function(_dereq_,module,exports){
|
|
@@ -16074,7 +16018,6 @@ module.exports = function (Utils, Konva) {
|
|
|
16074
16018
|
this._view = view;
|
|
16075
16019
|
this._lines = lines;
|
|
16076
16020
|
this._playheadPixel = 0;
|
|
16077
|
-
this._playheadLineAnimation = null;
|
|
16078
16021
|
this._playheadVisible = false;
|
|
16079
16022
|
this._playheadColor = peaks.options.playheadColor;
|
|
16080
16023
|
this._playheadTextColor = peaks.options.playheadTextColor;
|
|
@@ -16086,7 +16029,6 @@ module.exports = function (Utils, Konva) {
|
|
|
16086
16029
|
this._createPlayheadText(this._playheadTextColor);
|
|
16087
16030
|
}
|
|
16088
16031
|
this.fitToView();
|
|
16089
|
-
this.zoomLevelChanged();
|
|
16090
16032
|
this._peaks.on('segments.remove_all', this._onSegmentsRemoveAll.bind(this));
|
|
16091
16033
|
this._peaks.on('segments.remove', this._onSegmentsRemove.bind(this));
|
|
16092
16034
|
}
|
|
@@ -16111,21 +16053,6 @@ module.exports = function (Utils, Konva) {
|
|
|
16111
16053
|
PlayheadLayer.prototype.listening = function (bool) {
|
|
16112
16054
|
this._playheadLayer.listening(bool);
|
|
16113
16055
|
};
|
|
16114
|
-
PlayheadLayer.prototype.zoomLevelChanged = function () {
|
|
16115
|
-
var pixelsPerSecond = this._view.timeToPixels(1);
|
|
16116
|
-
var time;
|
|
16117
|
-
this._useAnimation = pixelsPerSecond >= 5;
|
|
16118
|
-
if (this._useAnimation) {
|
|
16119
|
-
if (this._peaks.player.isPlaying() && !this._playheadLineAnimation) {
|
|
16120
|
-
this._start();
|
|
16121
|
-
}
|
|
16122
|
-
} else {
|
|
16123
|
-
if (this._playheadLineAnimation) {
|
|
16124
|
-
time = this._peaks.player.getCurrentTime();
|
|
16125
|
-
this.stop(time);
|
|
16126
|
-
}
|
|
16127
|
-
}
|
|
16128
|
-
};
|
|
16129
16056
|
PlayheadLayer.prototype.fitToView = function () {
|
|
16130
16057
|
var height = this._view.getHeight();
|
|
16131
16058
|
this._playheadLine.points([
|
|
@@ -16208,9 +16135,6 @@ module.exports = function (Utils, Konva) {
|
|
|
16208
16135
|
};
|
|
16209
16136
|
PlayheadLayer.prototype.updatePlayheadTime = function (time) {
|
|
16210
16137
|
this._syncPlayhead(time);
|
|
16211
|
-
if (this._peaks.player.isPlaying()) {
|
|
16212
|
-
this._start();
|
|
16213
|
-
}
|
|
16214
16138
|
};
|
|
16215
16139
|
PlayheadLayer.prototype._syncPlayhead = function (time) {
|
|
16216
16140
|
var pixelIndex = this._view.timeToPixels(time);
|
|
@@ -16244,33 +16168,6 @@ module.exports = function (Utils, Konva) {
|
|
|
16244
16168
|
this._time = time;
|
|
16245
16169
|
this._playheadLayer.draw();
|
|
16246
16170
|
};
|
|
16247
|
-
PlayheadLayer.prototype._start = function () {
|
|
16248
|
-
var self = this;
|
|
16249
|
-
if (self._playheadLineAnimation) {
|
|
16250
|
-
self._playheadLineAnimation.stop();
|
|
16251
|
-
self._playheadLineAnimation = null;
|
|
16252
|
-
}
|
|
16253
|
-
if (!self._useAnimation) {
|
|
16254
|
-
return;
|
|
16255
|
-
}
|
|
16256
|
-
var lastPlayheadPosition = null;
|
|
16257
|
-
self._playheadLineAnimation = new Konva.Animation(function () {
|
|
16258
|
-
var time = self._peaks.player.getCurrentTime();
|
|
16259
|
-
var playheadPosition = self._view.timeToPixels(time);
|
|
16260
|
-
if (playheadPosition !== lastPlayheadPosition) {
|
|
16261
|
-
self._syncPlayhead(time);
|
|
16262
|
-
lastPlayheadPosition = playheadPosition;
|
|
16263
|
-
}
|
|
16264
|
-
}, self._playheadLayer);
|
|
16265
|
-
self._playheadLineAnimation.start();
|
|
16266
|
-
};
|
|
16267
|
-
PlayheadLayer.prototype.stop = function (time) {
|
|
16268
|
-
if (this._playheadLineAnimation) {
|
|
16269
|
-
this._playheadLineAnimation.stop();
|
|
16270
|
-
this._playheadLineAnimation = null;
|
|
16271
|
-
}
|
|
16272
|
-
this._syncPlayhead(time);
|
|
16273
|
-
};
|
|
16274
16171
|
PlayheadLayer.prototype.getPlayheadOffset = function () {
|
|
16275
16172
|
return this._playheadPixel - this._view.getFrameOffset();
|
|
16276
16173
|
};
|
|
@@ -19905,7 +19802,6 @@ module.exports = function (MouseDragHandler, PlayheadLayer, SourcesLayer, ModeLa
|
|
|
19905
19802
|
this.setFrameOffset(apexPixel - playheadOffsetPixels);
|
|
19906
19803
|
this.updateTimeline(this._frameOffset, undefined, undefined, true);
|
|
19907
19804
|
this._sourcesLayer.rescale(true);
|
|
19908
|
-
this._playheadLayer.zoomLevelChanged();
|
|
19909
19805
|
this._playheadLayer.updatePlayheadTime(currentTime);
|
|
19910
19806
|
this._peaks.emit('zoom.update', newScale, prevScale);
|
|
19911
19807
|
return true;
|
package/src/player.js
CHANGED
|
@@ -26,91 +26,8 @@ define([
|
|
|
26
26
|
|
|
27
27
|
self._peaks = peaks;
|
|
28
28
|
self._currentTime = 0;
|
|
29
|
-
self._isPlaying = false;
|
|
30
|
-
|
|
31
|
-
self._speed = 1;
|
|
32
|
-
|
|
33
|
-
self._segmentPlayInterval = null;
|
|
34
29
|
}
|
|
35
30
|
|
|
36
|
-
/**
|
|
37
|
-
* Set the playing speed.
|
|
38
|
-
*
|
|
39
|
-
* @param {Number} newSpeed The new speed, 1.0 is the normal (and default) speed.
|
|
40
|
-
*/
|
|
41
|
-
|
|
42
|
-
Player.prototype.setSpeed = function(newSpeed) {
|
|
43
|
-
this._speed = newSpeed;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Cleans up the player object, removing all event listeners from the
|
|
48
|
-
* associated media element.
|
|
49
|
-
*/
|
|
50
|
-
|
|
51
|
-
Player.prototype.destroy = function() {
|
|
52
|
-
if (this._segmentPlayInterval !== null) {
|
|
53
|
-
clearInterval(this._segmentPlayInterval);
|
|
54
|
-
this._segmentPlayInterval = null;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (this._playInterval !== null) {
|
|
58
|
-
clearInterval(this._playInterval);
|
|
59
|
-
this._playInterval = null;
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Starts playback.
|
|
65
|
-
*/
|
|
66
|
-
|
|
67
|
-
Player.prototype.play = function() {
|
|
68
|
-
if (!this._playInterval) {
|
|
69
|
-
var prevTime = performance.now();
|
|
70
|
-
var time;
|
|
71
|
-
var self = this;
|
|
72
|
-
|
|
73
|
-
this._isPlaying = true;
|
|
74
|
-
|
|
75
|
-
this._peaks.overrideInteractions(true, false);
|
|
76
|
-
|
|
77
|
-
this._playInterval = setInterval(function() {
|
|
78
|
-
time = performance.now();
|
|
79
|
-
self._currentTime += ((time - prevTime) / 1000) * self._speed;
|
|
80
|
-
prevTime = time;
|
|
81
|
-
self._peaks.emit('timeline.update', self._currentTime);
|
|
82
|
-
}, 20);
|
|
83
|
-
|
|
84
|
-
this._peaks.emit('timeline.play', this._currentTime);
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Pauses playback.
|
|
90
|
-
*/
|
|
91
|
-
|
|
92
|
-
Player.prototype.pause = function() {
|
|
93
|
-
if (this._playInterval) {
|
|
94
|
-
this._isPlaying = false;
|
|
95
|
-
|
|
96
|
-
clearInterval(this._playInterval);
|
|
97
|
-
this._playInterval = null;
|
|
98
|
-
|
|
99
|
-
this._peaks.overrideInteractions(false);
|
|
100
|
-
|
|
101
|
-
this._peaks.emit('timeline.pause', this._currentTime);
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* @returns {Boolean} <code>true</code> if playing, <code>false</code>
|
|
107
|
-
* otherwise.
|
|
108
|
-
*/
|
|
109
|
-
|
|
110
|
-
Player.prototype.isPlaying = function() {
|
|
111
|
-
return this._isPlaying;
|
|
112
|
-
};
|
|
113
|
-
|
|
114
31
|
/**
|
|
115
32
|
* Returns the current playback time position, in seconds.
|
|
116
33
|
*
|
|
@@ -135,49 +52,26 @@ define([
|
|
|
135
52
|
this._peaks.emit('timeline.seek', this._currentTime);
|
|
136
53
|
};
|
|
137
54
|
|
|
138
|
-
Player.prototype._seek = function(time) {
|
|
139
|
-
if (!Utils.isValidTime(time)) {
|
|
140
|
-
this._peaks.logger('peaks.player.seek(): parameter must be a valid time, in seconds');
|
|
141
|
-
return false;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
this._currentTime = Math.max(0, time);
|
|
145
|
-
return true;
|
|
146
|
-
};
|
|
147
|
-
|
|
148
55
|
/**
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
* @param {Segment} segment The segment denoting the time region to play.
|
|
56
|
+
* Update the time (variation of seek, with a different event).
|
|
152
57
|
*/
|
|
153
58
|
|
|
154
|
-
Player.prototype.
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
if (!segment ||
|
|
158
|
-
!Utils.isValidTime(segment.startTime) ||
|
|
159
|
-
!Utils.isValidTime(segment.endTime)) {
|
|
160
|
-
self._peaks.logger('peaks.player.playSegment(): parameter must be a segment object');
|
|
59
|
+
Player.prototype.update = function(time) {
|
|
60
|
+
if (!this._seek(time)) {
|
|
161
61
|
return;
|
|
162
62
|
}
|
|
163
63
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
// Set time to segment start time
|
|
168
|
-
self.seek(segment.startTime);
|
|
64
|
+
this._peaks.emit('timeline.update', this._currentTime);
|
|
65
|
+
};
|
|
169
66
|
|
|
170
|
-
|
|
171
|
-
|
|
67
|
+
Player.prototype._seek = function(time) {
|
|
68
|
+
if (!Utils.isValidTime(time)) {
|
|
69
|
+
this._peaks.logger('peaks.player.seek(): parameter must be a valid time, in seconds');
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
172
72
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
clearInterval(self._segmentPlayInterval);
|
|
176
|
-
self._segmentPlayInterval = null;
|
|
177
|
-
self.pause();
|
|
178
|
-
// self.seek(segment.endTime);
|
|
179
|
-
}
|
|
180
|
-
}, 10);
|
|
73
|
+
this._currentTime = Math.max(0, time);
|
|
74
|
+
return true;
|
|
181
75
|
};
|
|
182
76
|
|
|
183
77
|
return Player;
|
package/src/playhead-layer.js
CHANGED
|
@@ -31,7 +31,6 @@ define([
|
|
|
31
31
|
this._view = view;
|
|
32
32
|
this._lines = lines;
|
|
33
33
|
this._playheadPixel = 0;
|
|
34
|
-
this._playheadLineAnimation = null;
|
|
35
34
|
this._playheadVisible = false;
|
|
36
35
|
this._playheadColor = peaks.options.playheadColor;
|
|
37
36
|
this._playheadTextColor = peaks.options.playheadTextColor;
|
|
@@ -49,8 +48,6 @@ define([
|
|
|
49
48
|
|
|
50
49
|
this.fitToView();
|
|
51
50
|
|
|
52
|
-
this.zoomLevelChanged();
|
|
53
|
-
|
|
54
51
|
this._peaks.on('segments.remove_all', this._onSegmentsRemoveAll.bind(this));
|
|
55
52
|
this._peaks.on('segments.remove', this._onSegmentsRemove.bind(this));
|
|
56
53
|
}
|
|
@@ -89,38 +86,6 @@ define([
|
|
|
89
86
|
this._playheadLayer.listening(bool);
|
|
90
87
|
};
|
|
91
88
|
|
|
92
|
-
/**
|
|
93
|
-
* Decides whether to use an animation to update the playhead position.
|
|
94
|
-
*
|
|
95
|
-
* If the zoom level is such that the number of pixels per second of audio is
|
|
96
|
-
* low, we can use timeupdate events from the HTMLMediaElement to
|
|
97
|
-
* set the playhead position. Otherwise, we use an animation to update the
|
|
98
|
-
* playhead position more smoothly. The animation is CPU intensive, so we
|
|
99
|
-
* avoid using it where possible.
|
|
100
|
-
*/
|
|
101
|
-
|
|
102
|
-
PlayheadLayer.prototype.zoomLevelChanged = function() {
|
|
103
|
-
var pixelsPerSecond = this._view.timeToPixels(1.0);
|
|
104
|
-
var time;
|
|
105
|
-
|
|
106
|
-
this._useAnimation = pixelsPerSecond >= 5;
|
|
107
|
-
|
|
108
|
-
if (this._useAnimation) {
|
|
109
|
-
if (this._peaks.player.isPlaying() && !this._playheadLineAnimation) {
|
|
110
|
-
// Start the animation
|
|
111
|
-
this._start();
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
if (this._playheadLineAnimation) {
|
|
116
|
-
// Stop the animation
|
|
117
|
-
time = this._peaks.player.getCurrentTime();
|
|
118
|
-
|
|
119
|
-
this.stop(time);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
|
|
124
89
|
/**
|
|
125
90
|
* Resizes the playhead UI objects to fit the available space in the
|
|
126
91
|
* view.
|
|
@@ -252,10 +217,6 @@ define([
|
|
|
252
217
|
|
|
253
218
|
PlayheadLayer.prototype.updatePlayheadTime = function(time) {
|
|
254
219
|
this._syncPlayhead(time);
|
|
255
|
-
|
|
256
|
-
if (this._peaks.player.isPlaying()) {
|
|
257
|
-
this._start();
|
|
258
|
-
}
|
|
259
220
|
};
|
|
260
221
|
|
|
261
222
|
/**
|
|
@@ -313,48 +274,6 @@ define([
|
|
|
313
274
|
this._playheadLayer.draw();
|
|
314
275
|
};
|
|
315
276
|
|
|
316
|
-
/**
|
|
317
|
-
* Starts a playhead animation in sync with the media playback.
|
|
318
|
-
*
|
|
319
|
-
* @private
|
|
320
|
-
*/
|
|
321
|
-
|
|
322
|
-
PlayheadLayer.prototype._start = function() {
|
|
323
|
-
var self = this;
|
|
324
|
-
|
|
325
|
-
if (self._playheadLineAnimation) {
|
|
326
|
-
self._playheadLineAnimation.stop();
|
|
327
|
-
self._playheadLineAnimation = null;
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
if (!self._useAnimation) {
|
|
331
|
-
return;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
var lastPlayheadPosition = null;
|
|
335
|
-
|
|
336
|
-
self._playheadLineAnimation = new Konva.Animation(function() {
|
|
337
|
-
var time = self._peaks.player.getCurrentTime();
|
|
338
|
-
var playheadPosition = self._view.timeToPixels(time);
|
|
339
|
-
|
|
340
|
-
if (playheadPosition !== lastPlayheadPosition) {
|
|
341
|
-
self._syncPlayhead(time);
|
|
342
|
-
lastPlayheadPosition = playheadPosition;
|
|
343
|
-
}
|
|
344
|
-
}, self._playheadLayer);
|
|
345
|
-
|
|
346
|
-
self._playheadLineAnimation.start();
|
|
347
|
-
};
|
|
348
|
-
|
|
349
|
-
PlayheadLayer.prototype.stop = function(time) {
|
|
350
|
-
if (this._playheadLineAnimation) {
|
|
351
|
-
this._playheadLineAnimation.stop();
|
|
352
|
-
this._playheadLineAnimation = null;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
this._syncPlayhead(time);
|
|
356
|
-
};
|
|
357
|
-
|
|
358
277
|
/**
|
|
359
278
|
* Returns the position of the playhead marker, in pixels relative to the
|
|
360
279
|
* left hand side of the waveform view.
|
package/src/timeline-zoomview.js
CHANGED