Skip to content

Commit

Permalink
allow changing the stop-point of wavesurfer during playback (katspaug…
Browse files Browse the repository at this point in the history
…h#1795)

* allow changing the stop-point of wavesurfer during playback

When someone is playing back a loop or region, this allows for moving
the loop-point while playback is happening.

* add version marker

* clear last callback when adjusting playEnd
  • Loading branch information
osheroff authored and thijstriemstra committed Nov 6, 2019
1 parent 99e2109 commit 576c0af
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/mediaelement.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,11 @@ export default class MediaElement extends WebAudio {
/**
* Set the play end
*
* @private
* @param {number} end Where to end
*/
setPlayEnd(end) {
this.clearPlayEnd();

this._onPlayEnd = time => {
if (time >= end) {
this.pause();
Expand Down
10 changes: 10 additions & 0 deletions src/wavesurfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,16 @@ export default class WaveSurfer extends util.Observer {
return this.backend.play(start, end);
}

/**
* Set a point in seconds for playback to stop at.
*
* @param {number} position Position (in seconds) to stop at
* @version 3.3.0
*/
setPlayEnd(position) {
this.backend.setPlayEnd(position);
}

/**
* Stops and pauses playback
*
Expand Down
14 changes: 12 additions & 2 deletions src/webaudio.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export default class WebAudio extends util.Observer {
this.lastPlay = this.ac.currentTime;
/** @private */
this.startPosition = 0;
/** @private */
/** @private */
this.scheduledPause = null;
/** @private */
this.states = {
Expand Down Expand Up @@ -656,7 +656,7 @@ export default class WebAudio extends util.Observer {

this.scheduledPause = end;

this.source.start(0, start, end - start);
this.source.start(0, start);

if (this.ac.state == 'suspended') {
this.ac.resume && this.ac.resume();
Expand Down Expand Up @@ -715,4 +715,14 @@ export default class WebAudio extends util.Observer {
this.play();
}
}

/**
* Set a point in seconds for playback to stop at.
*
* @param {number} end Position to end at
* @version 3.3.0
*/
setPlayEnd(end) {
this.scheduledPause = end;
}
}

0 comments on commit 576c0af

Please sign in to comment.