@checksub_team/peaks_timeline 1.4.52 → 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 +31 -122
- package/src/player.js +12 -118
- package/src/playhead-layer.js +0 -81
- package/src/source-group.js +2 -3
- package/src/source.js +26 -6
- package/src/timeline-sources.js +2 -0
- package/src/timeline-zoomview.js +0 -2
- package/src/waveform-shape.js +1 -5
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
|
};
|
|
@@ -17675,7 +17572,7 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
|
|
|
17675
17572
|
});
|
|
17676
17573
|
var self = this;
|
|
17677
17574
|
var background = new Konva.Shape({
|
|
17678
|
-
fill: this._source.
|
|
17575
|
+
fill: this._source.backgroundColor,
|
|
17679
17576
|
stroke: this._source.borderColor,
|
|
17680
17577
|
strokeWidth: this._source.borderWidth,
|
|
17681
17578
|
sceneFunc: function (ctx, shape) {
|
|
@@ -17727,7 +17624,7 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
|
|
|
17727
17624
|
});
|
|
17728
17625
|
var self = this;
|
|
17729
17626
|
var background = new Konva.Shape({
|
|
17730
|
-
fill: this._source.
|
|
17627
|
+
fill: this._source.backgroundColor,
|
|
17731
17628
|
stroke: this._source.borderColor,
|
|
17732
17629
|
strokeWidth: this._source.borderWidth,
|
|
17733
17630
|
sceneFunc: function (ctx, shape) {
|
|
@@ -17957,7 +17854,6 @@ module.exports = function (WaveformBuilder, WaveformShape, Utils, Konva) {
|
|
|
17957
17854
|
var waveform = new WaveformShape({
|
|
17958
17855
|
layer: this._layer,
|
|
17959
17856
|
view: this._view,
|
|
17960
|
-
color: this._peaks.options.zoomWaveformColor,
|
|
17961
17857
|
source: this._source,
|
|
17962
17858
|
height: preview.group.height(),
|
|
17963
17859
|
url: preview.url
|
|
@@ -18204,7 +18100,10 @@ module.exports = function (Utils) {
|
|
|
18204
18100
|
throw new TypeError('peaks.sources.' + context + ': binaryUrl must be a string');
|
|
18205
18101
|
}
|
|
18206
18102
|
if (!Utils.isValidColor(options.color)) {
|
|
18207
|
-
|
|
18103
|
+
options.color = peaks.options.zoomWaveformColor;
|
|
18104
|
+
}
|
|
18105
|
+
if (!Utils.isValidColor(options.backgroundColor)) {
|
|
18106
|
+
throw new TypeError('peaks.sources.' + context + ': backgroundColor should be a valid CSS color');
|
|
18208
18107
|
}
|
|
18209
18108
|
if (!Utils.isValidColor(options.borderColor)) {
|
|
18210
18109
|
options.borderColor = options.color;
|
|
@@ -18271,7 +18170,7 @@ module.exports = function (Utils) {
|
|
|
18271
18170
|
options.wrapped = false;
|
|
18272
18171
|
}
|
|
18273
18172
|
}
|
|
18274
|
-
function Source(peaks, id, originId, elementId, title, url, previewUrl, binaryUrl, kind, subkind, duration, startTime, endTime, mediaStartTime, mediaEndTime, color, borderColor, selectedColor, textColor, borderWidth, wrapped, position, draggable, resizable, wrapping, previewHeight, binaryHeight) {
|
|
18173
|
+
function Source(peaks, id, originId, elementId, title, url, previewUrl, binaryUrl, kind, subkind, duration, startTime, endTime, mediaStartTime, mediaEndTime, color, backgroundColor, borderColor, selectedColor, textColor, borderWidth, wrapped, position, draggable, resizable, wrapping, previewHeight, binaryHeight) {
|
|
18275
18174
|
var opts = {
|
|
18276
18175
|
title: title,
|
|
18277
18176
|
url: url,
|
|
@@ -18285,6 +18184,7 @@ module.exports = function (Utils) {
|
|
|
18285
18184
|
mediaStartTime: mediaStartTime,
|
|
18286
18185
|
mediaEndTime: mediaEndTime,
|
|
18287
18186
|
color: color,
|
|
18187
|
+
backgroundColor: backgroundColor,
|
|
18288
18188
|
borderColor: borderColor,
|
|
18289
18189
|
selectedColor: selectedColor,
|
|
18290
18190
|
textColor: textColor,
|
|
@@ -18314,8 +18214,9 @@ module.exports = function (Utils) {
|
|
|
18314
18214
|
this._mediaStartTime = opts.mediaStartTime;
|
|
18315
18215
|
this._mediaEndTime = opts.mediaEndTime;
|
|
18316
18216
|
this._color = opts.color;
|
|
18217
|
+
this._backgroundColor = opts.backgroundColor;
|
|
18317
18218
|
this._borderColor = opts.borderColor;
|
|
18318
|
-
this._selectedColor = opts.selectedColor || Utils.shadeColor(opts.
|
|
18219
|
+
this._selectedColor = opts.selectedColor || Utils.shadeColor(opts.backgroundColor, 30);
|
|
18319
18220
|
this._textColor = opts.textColor;
|
|
18320
18221
|
this._borderWidth = opts.borderWidth;
|
|
18321
18222
|
this._wrapped = opts.wrapped;
|
|
@@ -18436,6 +18337,15 @@ module.exports = function (Utils) {
|
|
|
18436
18337
|
this._color = color;
|
|
18437
18338
|
}
|
|
18438
18339
|
},
|
|
18340
|
+
backgroundColor: {
|
|
18341
|
+
enumerable: true,
|
|
18342
|
+
get: function () {
|
|
18343
|
+
return this._backgroundColor;
|
|
18344
|
+
},
|
|
18345
|
+
set: function (backgroundColor) {
|
|
18346
|
+
this._backgroundColor = backgroundColor;
|
|
18347
|
+
}
|
|
18348
|
+
},
|
|
18439
18349
|
borderColor: {
|
|
18440
18350
|
enumerable: true,
|
|
18441
18351
|
get: function () {
|
|
@@ -18640,6 +18550,7 @@ module.exports = function (Utils) {
|
|
|
18640
18550
|
mediaStartTime: this.mediaStartTime,
|
|
18641
18551
|
mediaEndTime: this.mediaEndTime,
|
|
18642
18552
|
color: this.color,
|
|
18553
|
+
backgroundColor: this.backgroundColor,
|
|
18643
18554
|
borderColor: this.borderColor,
|
|
18644
18555
|
selectedColor: this.selectedColor,
|
|
18645
18556
|
textColor: this.textColor,
|
|
@@ -18666,8 +18577,9 @@ module.exports = function (Utils) {
|
|
|
18666
18577
|
this._mediaStartTime = opts.mediaStartTime;
|
|
18667
18578
|
this._mediaEndTime = opts.mediaEndTime;
|
|
18668
18579
|
this._color = opts.color;
|
|
18580
|
+
this._backgroundColor = opts.backgroundColor;
|
|
18669
18581
|
this._borderColor = opts.borderColor;
|
|
18670
|
-
this._selectedColor = opts.selectedColor || Utils.shadeColor(opts.
|
|
18582
|
+
this._selectedColor = opts.selectedColor || Utils.shadeColor(opts.backgroundColor, 30);
|
|
18671
18583
|
this._textColor = opts.textColor;
|
|
18672
18584
|
this._borderWidth = opts.borderWidth;
|
|
18673
18585
|
this._wrapped = opts.wrapped;
|
|
@@ -19363,6 +19275,7 @@ module.exports = function (Source, Utils) {
|
|
|
19363
19275
|
mediaStartTime: sourceToCut.mediaEndTime,
|
|
19364
19276
|
mediaEndTime: originalMediaEndTime,
|
|
19365
19277
|
color: sourceToCut.color,
|
|
19278
|
+
backgroundColor: sourceToCut.backgroundColor,
|
|
19366
19279
|
borderColor: sourceToCut.borderColor,
|
|
19367
19280
|
selectedColor: sourceToCut.selectedColor,
|
|
19368
19281
|
textColor: sourceToCut.textColor,
|
|
@@ -19388,7 +19301,7 @@ module.exports = function (Source, Utils) {
|
|
|
19388
19301
|
if (!Utils.isObject(options)) {
|
|
19389
19302
|
throw new TypeError('peaks.sources.add(): expected a Source object parameter');
|
|
19390
19303
|
}
|
|
19391
|
-
var source = new Source(this._peaks, options.id || this._getNextSourceId(), options.originId, options.elementId, options.title, options.url, options.previewUrl, options.binaryUrl, options.kind, options.subkind, options.duration, options.startTime, options.endTime, options.mediaStartTime, options.mediaEndTime, options.color, options.borderColor, options.selectedColor, options.textColor, options.borderWidth, options.wrapped, options.position, options.draggable, options.resizable, options.wrapping, options.previewHeight, options.binaryHeight);
|
|
19304
|
+
var source = new Source(this._peaks, options.id || this._getNextSourceId(), options.originId, options.elementId, options.title, options.url, options.previewUrl, options.binaryUrl, options.kind, options.subkind, options.duration, options.startTime, options.endTime, options.mediaStartTime, options.mediaEndTime, options.color, options.backgroundColor, options.borderColor, options.selectedColor, options.textColor, options.borderWidth, options.wrapped, options.position, options.draggable, options.resizable, options.wrapping, options.previewHeight, options.binaryHeight);
|
|
19392
19305
|
return source;
|
|
19393
19306
|
};
|
|
19394
19307
|
TimelineSources.prototype.getSources = function () {
|
|
@@ -19889,7 +19802,6 @@ module.exports = function (MouseDragHandler, PlayheadLayer, SourcesLayer, ModeLa
|
|
|
19889
19802
|
this.setFrameOffset(apexPixel - playheadOffsetPixels);
|
|
19890
19803
|
this.updateTimeline(this._frameOffset, undefined, undefined, true);
|
|
19891
19804
|
this._sourcesLayer.rescale(true);
|
|
19892
|
-
this._playheadLayer.zoomLevelChanged();
|
|
19893
19805
|
this._playheadLayer.updatePlayheadTime(currentTime);
|
|
19894
19806
|
this._peaks.emit('zoom.update', newScale, prevScale);
|
|
19895
19807
|
return true;
|
|
@@ -20424,7 +20336,7 @@ module.exports = function (Utils, Konva) {
|
|
|
20424
20336
|
return height - Utils.clamp(height - scaledAmplitude, 0, height);
|
|
20425
20337
|
}
|
|
20426
20338
|
function WaveformShape(options) {
|
|
20427
|
-
Konva.Shape.call(this, { fill: options.color });
|
|
20339
|
+
Konva.Shape.call(this, { fill: options.source.color });
|
|
20428
20340
|
this._layer = options.layer;
|
|
20429
20341
|
this._view = options.view;
|
|
20430
20342
|
this._source = options.source;
|
|
@@ -20434,9 +20346,6 @@ module.exports = function (Utils, Konva) {
|
|
|
20434
20346
|
this.hitFunc(this._waveformShapeHitFunc);
|
|
20435
20347
|
}
|
|
20436
20348
|
WaveformShape.prototype = Object.create(Konva.Shape.prototype);
|
|
20437
|
-
WaveformShape.prototype.setWaveformColor = function (color) {
|
|
20438
|
-
this.fill(color);
|
|
20439
|
-
};
|
|
20440
20349
|
WaveformShape.prototype._sceneFunc = function (context) {
|
|
20441
20350
|
var width = this._view.getWidth();
|
|
20442
20351
|
var waveformData = this._layer.getLoadedData(this._url).data;
|
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/source-group.js
CHANGED
|
@@ -399,7 +399,7 @@ define([
|
|
|
399
399
|
var self = this;
|
|
400
400
|
|
|
401
401
|
var background = new Konva.Shape({
|
|
402
|
-
fill: this._source.
|
|
402
|
+
fill: this._source.backgroundColor,
|
|
403
403
|
stroke: this._source.borderColor,
|
|
404
404
|
strokeWidth: this._source.borderWidth,
|
|
405
405
|
sceneFunc: function(ctx, shape) {
|
|
@@ -461,7 +461,7 @@ define([
|
|
|
461
461
|
var self = this;
|
|
462
462
|
|
|
463
463
|
var background = new Konva.Shape({
|
|
464
|
-
fill: this._source.
|
|
464
|
+
fill: this._source.backgroundColor,
|
|
465
465
|
stroke: this._source.borderColor,
|
|
466
466
|
strokeWidth: this._source.borderWidth,
|
|
467
467
|
sceneFunc: function(ctx, shape) {
|
|
@@ -757,7 +757,6 @@ define([
|
|
|
757
757
|
var waveform = new WaveformShape({
|
|
758
758
|
layer: this._layer,
|
|
759
759
|
view: this._view,
|
|
760
|
-
color: this._peaks.options.zoomWaveformColor,
|
|
761
760
|
source: this._source,
|
|
762
761
|
height: preview.group.height(),
|
|
763
762
|
url: preview.url
|
package/src/source.js
CHANGED
|
@@ -105,7 +105,13 @@ define([
|
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
if (!Utils.isValidColor(options.color)) {
|
|
108
|
-
|
|
108
|
+
options.color = peaks.options.zoomWaveformColor;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (!Utils.isValidColor(options.backgroundColor)) {
|
|
112
|
+
throw new TypeError(
|
|
113
|
+
'peaks.sources.' + context + ': backgroundColor should be a valid CSS color'
|
|
114
|
+
);
|
|
109
115
|
}
|
|
110
116
|
|
|
111
117
|
if (!Utils.isValidColor(options.borderColor)) {
|
|
@@ -220,9 +226,9 @@ define([
|
|
|
220
226
|
*/
|
|
221
227
|
|
|
222
228
|
function Source(peaks, id, originId, elementId, title, url, previewUrl, binaryUrl, kind,
|
|
223
|
-
subkind, duration, startTime, endTime, mediaStartTime, mediaEndTime, color,
|
|
224
|
-
selectedColor, textColor, borderWidth, wrapped, position, draggable, resizable,
|
|
225
|
-
previewHeight, binaryHeight) {
|
|
229
|
+
subkind, duration, startTime, endTime, mediaStartTime, mediaEndTime, color, backgroundColor,
|
|
230
|
+
borderColor, selectedColor, textColor, borderWidth, wrapped, position, draggable, resizable,
|
|
231
|
+
wrapping, previewHeight, binaryHeight) {
|
|
226
232
|
var opts = {
|
|
227
233
|
title: title,
|
|
228
234
|
url: url,
|
|
@@ -236,6 +242,7 @@ define([
|
|
|
236
242
|
mediaStartTime: mediaStartTime,
|
|
237
243
|
mediaEndTime: mediaEndTime,
|
|
238
244
|
color: color,
|
|
245
|
+
backgroundColor: backgroundColor,
|
|
239
246
|
borderColor: borderColor,
|
|
240
247
|
selectedColor: selectedColor,
|
|
241
248
|
textColor: textColor,
|
|
@@ -267,8 +274,9 @@ define([
|
|
|
267
274
|
this._mediaStartTime = opts.mediaStartTime;
|
|
268
275
|
this._mediaEndTime = opts.mediaEndTime;
|
|
269
276
|
this._color = opts.color;
|
|
277
|
+
this._backgroundColor = opts.backgroundColor;
|
|
270
278
|
this._borderColor = opts.borderColor;
|
|
271
|
-
this._selectedColor = opts.selectedColor || Utils.shadeColor(opts.
|
|
279
|
+
this._selectedColor = opts.selectedColor || Utils.shadeColor(opts.backgroundColor, 30);
|
|
272
280
|
this._textColor = opts.textColor;
|
|
273
281
|
this._borderWidth = opts.borderWidth;
|
|
274
282
|
this._wrapped = opts.wrapped;
|
|
@@ -396,6 +404,16 @@ define([
|
|
|
396
404
|
this._color = color;
|
|
397
405
|
}
|
|
398
406
|
},
|
|
407
|
+
backgroundColor: {
|
|
408
|
+
enumerable: true,
|
|
409
|
+
get: function() {
|
|
410
|
+
return this._backgroundColor;
|
|
411
|
+
},
|
|
412
|
+
|
|
413
|
+
set: function(backgroundColor) {
|
|
414
|
+
this._backgroundColor = backgroundColor;
|
|
415
|
+
}
|
|
416
|
+
},
|
|
399
417
|
borderColor: {
|
|
400
418
|
enumerable: true,
|
|
401
419
|
get: function() {
|
|
@@ -641,6 +659,7 @@ define([
|
|
|
641
659
|
mediaStartTime: this.mediaStartTime,
|
|
642
660
|
mediaEndTime: this.mediaEndTime,
|
|
643
661
|
color: this.color,
|
|
662
|
+
backgroundColor: this.backgroundColor,
|
|
644
663
|
borderColor: this.borderColor,
|
|
645
664
|
selectedColor: this.selectedColor,
|
|
646
665
|
textColor: this.textColor,
|
|
@@ -670,8 +689,9 @@ define([
|
|
|
670
689
|
this._mediaStartTime = opts.mediaStartTime;
|
|
671
690
|
this._mediaEndTime = opts.mediaEndTime;
|
|
672
691
|
this._color = opts.color;
|
|
692
|
+
this._backgroundColor = opts.backgroundColor;
|
|
673
693
|
this._borderColor = opts.borderColor;
|
|
674
|
-
this._selectedColor = opts.selectedColor || Utils.shadeColor(opts.
|
|
694
|
+
this._selectedColor = opts.selectedColor || Utils.shadeColor(opts.backgroundColor, 30);
|
|
675
695
|
this._textColor = opts.textColor;
|
|
676
696
|
this._borderWidth = opts.borderWidth;
|
|
677
697
|
this._wrapped = opts.wrapped;
|
package/src/timeline-sources.js
CHANGED
|
@@ -78,6 +78,7 @@ define([
|
|
|
78
78
|
mediaStartTime: sourceToCut.mediaEndTime,
|
|
79
79
|
mediaEndTime: originalMediaEndTime,
|
|
80
80
|
color: sourceToCut.color,
|
|
81
|
+
backgroundColor: sourceToCut.backgroundColor,
|
|
81
82
|
borderColor: sourceToCut.borderColor,
|
|
82
83
|
selectedColor: sourceToCut.selectedColor,
|
|
83
84
|
textColor: sourceToCut.textColor,
|
|
@@ -151,6 +152,7 @@ define([
|
|
|
151
152
|
options.mediaStartTime,
|
|
152
153
|
options.mediaEndTime,
|
|
153
154
|
options.color,
|
|
155
|
+
options.backgroundColor,
|
|
154
156
|
options.borderColor,
|
|
155
157
|
options.selectedColor,
|
|
156
158
|
options.textColor,
|
package/src/timeline-zoomview.js
CHANGED
package/src/waveform-shape.js
CHANGED
|
@@ -51,7 +51,7 @@ define(['./utils', 'konva'], function(Utils, Konva) {
|
|
|
51
51
|
|
|
52
52
|
function WaveformShape(options) {
|
|
53
53
|
Konva.Shape.call(this, {
|
|
54
|
-
fill: options.color
|
|
54
|
+
fill: options.source.color
|
|
55
55
|
});
|
|
56
56
|
|
|
57
57
|
this._layer = options.layer;
|
|
@@ -67,10 +67,6 @@ define(['./utils', 'konva'], function(Utils, Konva) {
|
|
|
67
67
|
|
|
68
68
|
WaveformShape.prototype = Object.create(Konva.Shape.prototype);
|
|
69
69
|
|
|
70
|
-
WaveformShape.prototype.setWaveformColor = function(color) {
|
|
71
|
-
this.fill(color);
|
|
72
|
-
};
|
|
73
|
-
|
|
74
70
|
WaveformShape.prototype._sceneFunc = function(context) {
|
|
75
71
|
var width = this._view.getWidth();
|
|
76
72
|
var waveformData = this._layer.getLoadedData(this._url).data;
|