Ian
Ian

Reputation: 1457

AudioContext doesn't appear to exist in Chrome 35

Why has this code started erroring in chrome 35? Not sure when it started but it used to work around November 2013.

try {
// Fix up for prefixing
window.AudioContext = window.AudioContext ? new window.AudioContext() :
       window.webkitAudioContext ? new window.webkitAudioContext() :
       window.mozAudioContext ? new window.mozAudioContext() :
       window.oAudioContext ? new window.oAudioContext() :
       window.msAudioContext ? new window.msAudioContext() :
       undefined;
context = new AudioContext();
}
catch(e) {
      console.log('Error');
      console.log(e);
}

Edit: To clarify, this turned out to be a badly caught issue with getUserMedia now requiring all three input arguments. I was missing the error function:

navigator.getUserMedia (

  // constraints
  {
     video: false,
     audio: true
  },

  // successCallback
  function(localMediaStream) {
     // Do something with the audio here
  },

  // errorCallback
  function(err) {
     console.log("The following error occured: " + err);
  }
);

Upvotes: 0

Views: 1130

Answers (1)

cwilso
cwilso

Reputation: 13908

Chrome 35 started supporting AudioContext.

Why are you new()ing the AudioContexts in lines 3-7?

This is better captured, BTW, as:

window.AudioContext = window.AudioContext || window.webkitAudioContext;
context = new AudioContext();

There's no vendor-prefixed version in any browser other than webkitAudioContext.

Upvotes: 3

Related Questions