wave.js icon indicating copy to clipboard operation
wave.js copied to clipboard

Visualise Audio with muted audio

Open becasmar opened this issue 3 years ago • 1 comments

Is there a way you could implement visualising audio while the audio tag is muted? I want the bars to jump on autoplay but the user has to unmute it for a better UX. In a previous issue, someone suggested { connectDestination: false } but that no longer works

becasmar avatar Jul 14 '22 05:07 becasmar

It's an interesting thing. I need something like that too.

cyntler avatar Oct 10 '22 21:10 cyntler

Instead of this line add the following code:

this._volume = this._audioContext.createGain();
// Set this to 1 if you want sound at startup 
// or implement code to set the desired value by passing it as one of the constructor's arguments 
this._volume.gain.value = 0; 
this._audioAnalyser.connect(this._volume);
this._volume.connect(this._audioContext.destination);

Then in order for the user to be able to turn on/off the sound by themselves add this mute/unmute method and bind it to a button/switch in your UI:

public mute(): void {
  this._volume.gain.value = this._volume.gain.value === 1 ? 0 : 1;
}

I could prepare a PR for this if @foobar404 is interested. Let me know what you think. Thanks!

polomoshnov avatar Nov 16 '22 01:11 polomoshnov