From be778b27a9702432298378c41f39a70008743d26 Mon Sep 17 00:00:00 2001 From: Guillaume Villena Date: Sun, 2 Oct 2016 19:13:21 +0200 Subject: [PATCH] Now possible to make loop in select mode #15 --- src/Playlist.js | 26 +++++++++++++++++++++++--- src/Playout.js | 1 - 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/Playlist.js b/src/Playlist.js index 7f0c86cd..07ed25d7 100644 --- a/src/Playlist.js +++ b/src/Playlist.js @@ -31,6 +31,7 @@ export default class { this.fadeType = "logarithmic"; this.masterGain = 1; this.speed = 1; + this.loopNumber = 0; } initRecorder(stream) { @@ -133,6 +134,10 @@ export default class { this.setSpeed(speed); }); + ee.on('loopnumber', (number) => { + this.setLoop(number); + }); + ee.on('select', (start, end, track) => { if (this.isPlaying()) { this.lastSeeked = start; @@ -478,6 +483,11 @@ export default class { }); } + setLoop(number) { + this.loopNumber = number + } + + setSpeed(speed) { this.speed = (speed >= 0.5 && speed <= 4) ? speed : 1; if (this.isPlaying()) @@ -720,9 +730,19 @@ export default class { ); } else { - if ((cursorPos + elapsed) >= - (this.isSegmentSelection()) ? selection.end : this.duration) { - this.ee.emit('finished'); + if ((cursorPos + elapsed) >= (this.isSegmentSelection()) ? selection.end : this.duration) { + if (this.loopNumber > 0) { + this.loopNumber--; + this.ee.emit('newloop', this.loopNumber); + this.restartPlayFrom(selection.start, selection.end) + } + else if (this.loopNumber == -1) { + this.ee.emit('newloop', this.loopNumber); + this.restartPlayFrom(selection.start, selection.end) + + } + else + this.ee.emit('finished'); } this.stopAnimation(); diff --git a/src/Playout.js b/src/Playout.js index ef9ce6b8..d9448373 100644 --- a/src/Playout.js +++ b/src/Playout.js @@ -102,7 +102,6 @@ export default class { } setSpeed(speed) { - console.log("callaed ! " + speed); this.speed = speed; }