Created
October 14, 2013 20:10
-
-
Save joseph/6981446 to your computer and use it in GitHub Desktop.
The first function is specific to my Monocle-based app. But the second one is arguably useful, despite the name. It creates an AudioBuffer of the smallest viable mp3 (per http://www.hydrogenaudio.org/forums//lofiversion/index.php/t26315.html) and plays it immediately. You would invoke this from a click or touch event to "unlock" the AudioContext…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function panderToMobileSafari() { | |
if (!Monocle.Browser.is.MobileSafari || p.pandered) { return; } | |
oneHandClapping(p.context); | |
p.pandered = true; | |
debug('Pandered to MobileSafari.'); | |
} | |
function oneHandClapping(audioCtx) { | |
var arr = [ | |
0xFF,0xF3,0x14,0xC4,0x00,0x00,0x00,0x03,0x48,0x01,0x40,0x00, | |
0x00,0x4C,0x41,0x4D,0x45,0x33,0x2E,0x39,0x36,0x2E,0x31,0x55, | |
0xFF,0xF3,0x14,0xC4,0x0B,0x00,0x00,0x03,0x48,0x01,0x80,0x00, | |
0x00,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55 | |
]; | |
var buf = new ArrayBuffer(arr.length); | |
var bytes = new Uint8Array(buf); | |
for (var i = 0, ii = arr.length; i < ii; ++i) { bytes[i] = arr[i]; } | |
audioCtx.createBuffer(buf, false); | |
var snd = audioCtx.createBufferSource(); | |
snd.connect(audioCtx.destination); | |
snd.start(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment