Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReferenceError: AudioContext not defined

I'm trying to use the RecorderJS library (https://github.com/mattdiamond/Recorderjs) which requires me to have an AudioContext. However, when declaring the AudioContext at the very beginning of my script, I am getting an error in the console on page load that says "ReferenceError: AudioContext not defined." As anyone else ever encountered issues with the AudioContext like this? I've posted both a snippet of my JS, and the HTML where everything is being included. Thanks in advance!

JS:

var audioContext = new AudioContext();
var audioInput = null, inputPoint = null, audioRecorder = null;

$(document).ready(function(){
    // recording stuff
});

HTML:

<!DOCTYPE html>
<html>
    <head>
        <title>Recording</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <link rel='stylesheet' type='text/css' href='stylesheet.css'/>
        <script src="http://cwilso.github.io/AudioContext-MonkeyPatch/AudioContextMonkeyPatch.js"></script>
        <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
        <script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
        <script src="recorder.js"></script>
        <script src="script.js"></script>
    </head>
    <body>
        <button class="record" type='button'>Record</button>
    </body>
</html>
like image 569
Frank Cangialosi Avatar asked Oct 04 '22 01:10

Frank Cangialosi


1 Answers

Put this at the very beginning of your script (it's also in main.js in Matt Diamond's example):

window.AudioContext = window.AudioContext || window.webkitAudioContext;

This loads the correct AudioContext independent of your browser.

like image 105
Lewistrick Avatar answered Oct 11 '22 16:10

Lewistrick