Skip to content

Commit

Permalink
Merge pull request katspaugh#574 from jbeyer05/fix-seek-region-in-out…
Browse files Browse the repository at this point in the history
…-events

Fixes issue katspaugh#425 where region-out is not triggered when seeking out of current region
  • Loading branch information
katspaugh committed Nov 9, 2015
2 parents 85ff34d + a6afe8e commit e01ecaf
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions plugin/wavesurfer.regions.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,29 +269,27 @@ WaveSurfer.Region = {
bindInOut: function () {
var my = this;

var onPlay = function () {
my.firedIn = false;
my.firedOut = false;
};
my.firedIn = false;
my.firedOut = false;

var onProcess = function (time) {
if (!my.firedIn && my.start <= time && my.end > time) {
my.firedIn = true;
my.firedOut = false;
my.fireEvent('in');
my.wavesurfer.fireEvent('region-in', my);
}
if (!my.firedOut && my.firedIn && my.end <= Math.round(time * 100) / 100) {
if (!my.firedOut && my.firedIn && (my.start >= Math.round(time * 100) / 100 || my.end <= Math.round(time * 100) / 100)) {
my.firedOut = true;
my.firedIn = false;
my.fireEvent('out');
my.wavesurfer.fireEvent('region-out', my);
}
};

this.wavesurfer.on('play', onPlay);
this.wavesurfer.backend.on('audioprocess', onProcess);

this.on('remove', function () {
my.wavesurfer.un('play', onPlay);
my.wavesurfer.backend.un('audioprocess', onProcess);
});

Expand Down

0 comments on commit e01ecaf

Please sign in to comment.