Skip to content

Instantly share code, notes, and snippets.

@jsantell
Created August 5, 2012 15:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsantell/3265344 to your computer and use it in GitHub Desktop.
Save jsantell/3265344 to your computer and use it in GitHub Desktop.
Web Audio API, proc audio / media element source Safari bug
<!DOCTYPE html>
<html>
<head>
<title>Web Audio API Test</title>
<style>#data{ color: #ff0077; font-weight: bold;}</style>
</head>
<body>
<h1>Processing audio from Media Element Source</h1>
<h2>Works in Chrome, fails in Safari</h2>
<audio controls="controls">
<source src="test.mp3" type="audio/mpeg" />
<source src="test.ogg" type="audio/ogg" />
</audio>
<div id="data">Data not yet found</div>
<script>
(function () {
var ctx, proc, src, color,
audio = document.getElementsByTagName('audio')[0],
dataEl = document.getElementById('data');
audio.readyState < 3 ?
audio.addEventListener('canplay', connect) :
connect();
function connect () {
ctx = new webkitAudioContext(),
proc = ctx.createJavaScriptNode(2048),
src = ctx.createMediaElementSource(audio);
proc.onaudioprocess = function (e) {
var d = e.inputBuffer.getChannelData(0)[0];
if (d) {
color || (color = dataEl.style.color = '#aaee22');
dataEl.innerHTML = 'Data found: ' + d;
}
}
src.connect( proc );
src.connect( ctx.destination );
proc.connect( ctx.destination );
}
})();
</script>
<!-- View at http://screamingrobots.com/misc/safariaudiobug/ -->
</body>
</html>
@dersvenhesse
Copy link

It's working for me in current Safari 6.0.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment