pizzicato icon indicating copy to clipboard operation
pizzicato copied to clipboard

Solution for: "The AudioContext was not allowed to start."

Open dkozar opened this issue 5 years ago • 1 comments

Most of the time, when starting my application (yes, there is some randomness involved) , I'm getting this message as the 1st line in browser console:

console

Pizzicato.min.js:44 The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page. https://goo.gl/7K7WLu
(anonymous) @ Pizzicato.min.js:44
(anonymous) @ Pizzicato.min.js:1045
./node_modules/pizzicato/distr/Pizzicato.min.js @ Pizzicato.min.js:1045
__webpack_require__ @ bootstrap:781
fn @ bootstrap:149

Here is the place in Pizzicato.js triggering that message:

here

However, this is just a warning. The application actually doesn't crash or anything.

What happens after that is: if Sound accessing user microphone is is created, that sound is muted (microphone cannot be heard).

The link in the error message actually explains what has to be done: https://goo.gl/7K7WLu

In user action code (i.e. when some UI element is clicked, for instance a button "Start recording" or similar), this has to be called before creating any sounds:

Pizzicato.context.resume();

Note that (of course) if Pizzicato is not available, first you have to import it:

import Pizzicato from "pizzicato";

Here's a pen I created: https://codepen.io/dkozar/pen/XwxbjY

Try removing the Pizzicato.context.resume() line and see for yourself that whenever the The AudioContext was not allowed to start message is displayed in the console, the microphone is muted.

dkozar avatar May 30 '19 23:05 dkozar

Is there any solution for mobile?

SrFortes avatar Jun 03 '22 04:06 SrFortes