@checksub_team/peaks_timeline 1.4.53 → 1.5.1
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 +28 -111
- package/src/marker-factories.js +4 -1
- package/src/player.js +12 -118
- package/src/playhead-layer.js +0 -81
- package/src/segment.js +10 -0
- package/src/timeline-segments.js +21 -0
- package/src/timeline-zoomview.js +0 -2
package/package.json
CHANGED
package/peaks.js
CHANGED
|
@@ -15587,7 +15587,7 @@ module.exports = function (DefaultSegmentMarker, Utils, Konva) {
|
|
|
15587
15587
|
y: options.y,
|
|
15588
15588
|
width: options.width,
|
|
15589
15589
|
height: options.height,
|
|
15590
|
-
text: Utils.removeLineBreaks(options.segment.labelText),
|
|
15590
|
+
text: '#' + options.segment.relativeId + ' ' + Utils.removeLineBreaks(options.segment.labelText),
|
|
15591
15591
|
textAlign: 'left',
|
|
15592
15592
|
verticalAlign: 'middle',
|
|
15593
15593
|
wrap: 'none',
|
|
@@ -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
|
};
|
|
@@ -16784,6 +16681,7 @@ module.exports = function (Utils) {
|
|
|
16784
16681
|
this._line = opts.line;
|
|
16785
16682
|
this._indicators = opts.indicators;
|
|
16786
16683
|
this._minSize = peaks.options.minSegmentSize;
|
|
16684
|
+
this._relativeId = 0;
|
|
16787
16685
|
if (shouldNotifyUpdate) {
|
|
16788
16686
|
peaks.emit('segments.updated', [this]);
|
|
16789
16687
|
}
|
|
@@ -16878,6 +16776,15 @@ module.exports = function (Utils) {
|
|
|
16878
16776
|
get: function () {
|
|
16879
16777
|
return this._minSize;
|
|
16880
16778
|
}
|
|
16779
|
+
},
|
|
16780
|
+
relativeId: {
|
|
16781
|
+
enumerable: true,
|
|
16782
|
+
get: function () {
|
|
16783
|
+
return this._relativeId;
|
|
16784
|
+
},
|
|
16785
|
+
set: function (newId) {
|
|
16786
|
+
this._relativeId = newId;
|
|
16787
|
+
}
|
|
16881
16788
|
}
|
|
16882
16789
|
});
|
|
16883
16790
|
Segment.prototype.update = function (options) {
|
|
@@ -19284,8 +19191,18 @@ module.exports = function (Colors, Segment, Utils) {
|
|
|
19284
19191
|
segments.forEach(function (segment) {
|
|
19285
19192
|
self._addSegment(segment);
|
|
19286
19193
|
});
|
|
19194
|
+
this.refreshRelativeIds();
|
|
19287
19195
|
this._peaks.emit('segments.add', segments);
|
|
19288
19196
|
};
|
|
19197
|
+
TimelineSegments.prototype.refreshRelativeIds = function () {
|
|
19198
|
+
var idsByPosition = {};
|
|
19199
|
+
this._segments.sort(function (a, b) {
|
|
19200
|
+
return a.startTime - b.startTime;
|
|
19201
|
+
}).forEach(function (segment) {
|
|
19202
|
+
segment.relativeId = (idsByPosition[segment.line] || 0) + 1;
|
|
19203
|
+
idsByPosition[segment.line] = segment.relativeId;
|
|
19204
|
+
});
|
|
19205
|
+
};
|
|
19289
19206
|
TimelineSegments.prototype._findSegment = function (predicate) {
|
|
19290
19207
|
var indexes = [];
|
|
19291
19208
|
for (var i = 0, length = this._segments.length; i < length; i++) {
|
|
@@ -19308,6 +19225,7 @@ module.exports = function (Colors, Segment, Utils) {
|
|
|
19308
19225
|
TimelineSegments.prototype._removeSegments = function (predicate) {
|
|
19309
19226
|
var indexes = this._findSegment(predicate);
|
|
19310
19227
|
var removed = this._removeIndexes(indexes);
|
|
19228
|
+
this.refreshRelativeIds();
|
|
19311
19229
|
this._peaks.emit('segments.remove', removed);
|
|
19312
19230
|
return removed;
|
|
19313
19231
|
};
|
|
@@ -19905,7 +19823,6 @@ module.exports = function (MouseDragHandler, PlayheadLayer, SourcesLayer, ModeLa
|
|
|
19905
19823
|
this.setFrameOffset(apexPixel - playheadOffsetPixels);
|
|
19906
19824
|
this.updateTimeline(this._frameOffset, undefined, undefined, true);
|
|
19907
19825
|
this._sourcesLayer.rescale(true);
|
|
19908
|
-
this._playheadLayer.zoomLevelChanged();
|
|
19909
19826
|
this._playheadLayer.updatePlayheadTime(currentTime);
|
|
19910
19827
|
this._peaks.emit('zoom.update', newScale, prevScale);
|
|
19911
19828
|
return true;
|
package/src/marker-factories.js
CHANGED
|
@@ -71,7 +71,10 @@ define([
|
|
|
71
71
|
y: options.y,
|
|
72
72
|
width: options.width,
|
|
73
73
|
height: options.height,
|
|
74
|
-
text:
|
|
74
|
+
text: '#'
|
|
75
|
+
+ options.segment.relativeId
|
|
76
|
+
+ ' '
|
|
77
|
+
+ Utils.removeLineBreaks(options.segment.labelText),
|
|
75
78
|
textAlign: 'left',
|
|
76
79
|
verticalAlign: 'middle',
|
|
77
80
|
wrap: 'none',
|
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/segment.js
CHANGED
|
@@ -131,6 +131,7 @@ define([
|
|
|
131
131
|
this._line = opts.line;
|
|
132
132
|
this._indicators = opts.indicators;
|
|
133
133
|
this._minSize = peaks.options.minSegmentSize;
|
|
134
|
+
this._relativeId = 0;
|
|
134
135
|
|
|
135
136
|
if (shouldNotifyUpdate) {
|
|
136
137
|
peaks.emit('segments.updated', [this]);
|
|
@@ -229,6 +230,15 @@ define([
|
|
|
229
230
|
get: function() {
|
|
230
231
|
return this._minSize;
|
|
231
232
|
}
|
|
233
|
+
},
|
|
234
|
+
relativeId: {
|
|
235
|
+
enumerable: true,
|
|
236
|
+
get: function() {
|
|
237
|
+
return this._relativeId;
|
|
238
|
+
},
|
|
239
|
+
set: function(newId) {
|
|
240
|
+
this._relativeId = newId;
|
|
241
|
+
}
|
|
232
242
|
}
|
|
233
243
|
});
|
|
234
244
|
|
package/src/timeline-segments.js
CHANGED
|
@@ -251,9 +251,28 @@ define([
|
|
|
251
251
|
self._addSegment(segment);
|
|
252
252
|
});
|
|
253
253
|
|
|
254
|
+
this.refreshRelativeIds();
|
|
255
|
+
|
|
254
256
|
this._peaks.emit('segments.add', segments);
|
|
255
257
|
};
|
|
256
258
|
|
|
259
|
+
/**
|
|
260
|
+
* Set relative ids for all segments.
|
|
261
|
+
*
|
|
262
|
+
* @private
|
|
263
|
+
*/
|
|
264
|
+
|
|
265
|
+
TimelineSegments.prototype.refreshRelativeIds = function() {
|
|
266
|
+
var idsByPosition = {};
|
|
267
|
+
|
|
268
|
+
this._segments.sort(function(a, b) {
|
|
269
|
+
return a.startTime - b.startTime;
|
|
270
|
+
}).forEach(function(segment) {
|
|
271
|
+
segment.relativeId = (idsByPosition[segment.line] || 0) + 1;
|
|
272
|
+
idsByPosition[segment.line] = segment.relativeId;
|
|
273
|
+
});
|
|
274
|
+
};
|
|
275
|
+
|
|
257
276
|
/**
|
|
258
277
|
* Returns the indexes of segments that match the given predicate.
|
|
259
278
|
*
|
|
@@ -317,6 +336,8 @@ define([
|
|
|
317
336
|
|
|
318
337
|
var removed = this._removeIndexes(indexes);
|
|
319
338
|
|
|
339
|
+
this.refreshRelativeIds();
|
|
340
|
+
|
|
320
341
|
this._peaks.emit('segments.remove', removed);
|
|
321
342
|
|
|
322
343
|
return removed;
|
package/src/timeline-zoomview.js
CHANGED