Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Autoplay audio on the ipad or iphone using webkitaudiocontext instead of audio tag
AudioSFX = function( _p, _autoplay ) {
var self = this;
var parent = _p;
this.sounds = new Array();
this.context = new webkitAudioContext();
this.autoplay = _autoplay; = function( sound ) {
var source = self.context.createBufferSource();
source.buffer = self.sounds[sound];
source.connect( self.context.destination );
source.noteOn( 0 );
this.load = function() {
var request = new XMLHttpRequest();
request.addEventListener( 'load', function(e) {
self.context.decodeAudioData( request.response, function(decoded_data) {
self.sounds[0] = decoded_data;
if( self.autoplay ) {;
}, function(e){
}, false); 'GET', 'wav/sfx.wav', true );
request.responseType = "arraybuffer";
var sfx = new AudioSFX( this, true ); // true for autoplay

This comment has been minimized.

Copy link

commented Jul 23, 2013

doesn't seem to work


This comment has been minimized.

Copy link
Owner Author

commented Oct 19, 2013

really? they might have updated safari, but this was working in production. do you have a sample project?


This comment has been minimized.

Copy link

commented Dec 25, 2013

it seems to be didn't work
i had tested it

test it in on ios 6 safari

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.