Skip to content

Commit

Permalink
fix mute
Browse files Browse the repository at this point in the history
  • Loading branch information
thijstriemstra committed May 7, 2019
1 parent 764e639 commit a0d189e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/mediaelement.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export default class MediaElement extends WebAudio {
/** @private */
this.volume = 1;
/** @private */
this.isMuted = false;
/** @private */
this.buffer = null;
/** @private */
this.onPlayEnd = null;
Expand Down Expand Up @@ -160,7 +162,8 @@ export default class MediaElement extends WebAudio {
});

media.addEventListener('volumechange', event => {
if (media.muted) {
this.isMuted = media.muted;
if (this.isMuted) {
this.volume = 0;
} else {
this.volume = media.volume;
Expand All @@ -172,6 +175,7 @@ export default class MediaElement extends WebAudio {
this.peaks = peaks;
this.onPlayEnd = null;
this.buffer = null;
this.isMuted = media.muted;
this.setPlaybackRate(this.playbackRate);
this.setVolume(this.volume);
}
Expand Down
10 changes: 6 additions & 4 deletions src/wavesurfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -658,10 +658,12 @@ export default class WaveSurfer extends util.Observer {
});

this.backend.on('volume', () => {
if (this.getVolume() === 0) {
this.isMuted = true;
} else {
this.isMuted = false;
let newVolume = this.getVolume();
this.fireEvent('volume', newVolume);

if (this.backend.isMuted !== this.isMuted) {
this.isMuted = this.backend.isMuted;
this.fireEvent('mute', this.isMuted);
}
});
}
Expand Down

0 comments on commit a0d189e

Please sign in to comment.