dangerChihuahua007
dangerChihuahua007

Reputation: 20895

How do I determine which AudioContext constructor to use in Safari?

I'm using the HTML5 web audio API, and I'm trying to dynamically determine which AudioContext constructor to use via

var constructor = AudioContext || webkitAudioContext;
var context = new constructor();

However, with this code, Safari quips:

ReferenceError: Can't find variable: AudioContext

For starters, I didn't even know that ReferenceErrors exist in javascript, since undefined variables by default take on the undefined value. Safari's implementation of javascript apparently differs in big ways from that of Chrome, even though both use webkit engines ...

How do I determine which constructor to use without triggering this error?

Upvotes: 1

Views: 1571

Answers (1)

cwilso
cwilso

Reputation: 13908

Try window.AudioContext instead.

Upvotes: 4

Related Questions