Search code examples
javascriptangularjshtml5-audio

The AudioContext was not allowed to start. AngularJS Recorder Chrome 71


I've been using AngularAudioRecorder (AngularJS) for the last 4 years and with the last Chrome update I'm getting the following error:

The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page.
init @ angular-audio-recorder.js: 861

Code:

getPermission: function () {
      navigator.getUserMedia({
        "audio": true
      }, html5HandlerConfig.gotStream, html5HandlerConfig.failStream);
    },
    init: function () {
      service.isHtml5 = true;
      var AudioContext = window.AudioContext || window.webkitAudioContext;
      if (AudioContext && !html5AudioProps.audioContext) {
        html5AudioProps.audioContext = new AudioContext();
      }

      if (localStorage.getItem("permission") !== null) {
        //to get permission from browser cache for returning user
        html5HandlerConfig.getPermission();
      }
    }
  };

Please find the full code here: Angular Audio Recorder

Thank you for any help you can offer


Solution

  • I solved the problem. Finally resumed the paused AudioContext with:

    html5AudioProps.audioContext.resume().then(() => {
         var audioContext = html5AudioProps.audioContext;
    })
    

    Inside the function that starts the recording.