0

I was working with web audio API and I was following the code from https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/suspend to resume and suspend audio context. The suspending part is working but I can't resume after suspension.

window.AudioContext = window.AudioContext || window.webkitAudioContext;
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia;
window.URL = window.URL || window.webkitURL;

// Store the instance of AudioContext globally
audio_context = new AudioContext;

if(audio_context.state === 'running') {
  audio_context.suspend();

  } else if(audio_context.state === 'suspended') {
  alert("Resumed");
  //audio_context.resume();

  audio_context.resume().then(function() {
    // susresBtn.textContent = 'Suspend context';
  });
}
Lauren Rutledge
  • 1,195
  • 5
  • 18
  • 27
Tauseef Mamun
  • 126
  • 1
  • 3
  • 11

1 Answers1

0

Figured it out, this has to come from a user interaction like button click

Tauseef Mamun
  • 126
  • 1
  • 3
  • 11