Skip to content

Commit

Permalink
Listen to and relay play and pause events on media element (#1104)
Browse files Browse the repository at this point in the history
* Listen to and relay play and pause events on media element

* Corrected the 'pause' event label

* removed play and pause emits from respective functions
  • Loading branch information
nlicitra authored and katspaugh committed Jun 8, 2017
1 parent bc57ec8 commit dcd8b55
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/mediaelement.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ WaveSurfer.util.extend(WaveSurfer.MediaElement, {
my.fireEvent('finish');
});

// Listen to and relay play and pause events to enable
// playback control from the external media element
media.addEventListener('play', function () {
my.fireEvent('play');
});

media.addEventListener('pause', function () {
my.fireEvent('pause');
});

this.media = media;
this.peaks = peaks;
this.onPlayEnd = null;
Expand Down Expand Up @@ -171,7 +181,6 @@ WaveSurfer.util.extend(WaveSurfer.MediaElement, {
this.seekTo(start);
this.media.play();
end && this.setPlayEnd(end);
this.fireEvent('play');
},

/**
Expand All @@ -180,7 +189,6 @@ WaveSurfer.util.extend(WaveSurfer.MediaElement, {
pause: function () {
this.media && this.media.pause();
this.clearPlayEnd();
this.fireEvent('pause');
},

setPlayEnd: function (end) {
Expand Down

0 comments on commit dcd8b55

Please sign in to comment.