wave.js
wave.js copied to clipboard
Visualise Audio with muted audio
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
It's an interesting thing. I need something like that too.
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!