Permalink
Browse files

Fix sound loading on iOS devices

SM2 uses a global audio object so we were not getting events for each
sound object as expected. It's not possible to preload multiple sounds
in parallel with only a single audio element. We'll skip preload of
sounds when SM2 is using a global audio element.
  • Loading branch information...
1 parent 5a918ac commit 57042b2bede82179f633fc14218c0ced31033d1d @joelfillmore joelfillmore committed Jan 12, 2012
Showing with 14 additions and 2 deletions.
  1. +1 −1 PxLoader.js
  2. +13 −1 PxLoaderSound.js
View
@@ -127,8 +127,8 @@ function PxLoader(settings) {
// trigger requests for each resource
for (var i = 0, len = entries.length; i < len; i++) {
var entry = entries[i];
- entry.resource.start(this);
entry.status = ResourceState.WAITING;
+ entry.resource.start(this);
}
// do an initial status check soon since items may be loaded from the cache
View
@@ -38,7 +38,19 @@ function PxLoaderSound(id, url, tags, priority) {
this.start = function(pxLoader) {
// we need the loader ref so we can notify upon completion
loader = pxLoader;
- this.sound['load']();
+
+ // On iOS, soundManager2 uses a global audio object so we can't
+ // preload multiple sounds. We'll have to hope they load quickly
+ // when we need to play them. Unfortunately, SM2 doesn't expose
+ // a property to indicate its using a global object. For now we'll
+ // use the same test they do: only when on an iDevice
+ var iDevice = navigator.userAgent.match(/(ipad|iphone|ipod)/i);
+ if (iDevice) {
+ loader.onTimeout(self);
+ }
+ else {
+ this.sound['load']();
+ }
};
this.checkStatus = function() {

0 comments on commit 57042b2

Please sign in to comment.