I’m confused

iPad weirdness with multiple sounds

Hi,
I'm trying to load a bunch of short mp3-encoded sounds (1-2 seconds) and trigger them from mouse/touch events in a canvas. It works fine with the flash player, but I've noticed some weird stuff happening on the iPad. The first sound usually plays fine, but then the second sound is dropped, or loops, or is delayed. I realise HTML5 support is newish, so I pared the code back to plain Javascript (ie. without SoundManager) to try and figure out exactly what was happening. This test code contains just two sounds, which are triggered from button events.

http://stewartgreenhill.com/test/audi...

On Safari/OSX it works fine, although Safari does not dispatch 'playing' events after a sound has been played once.

On the iPad, the sounds play OK, but when switching between sounds it seems to fail its first attempt to play a new sound. That is, if I play:
A A B B A B A A
I get:
A A [silent] B [silent] [silent] [silent] A
The 'ended' event is dispatched immediately after the 'playing' event, as if the sound has zero duration. Like desktop Safari, it doesn't dispatch 'playing' once a sound has been played the first time.

Has anyone else noticed problems like this on the iPad? It looks like an Apple bug rather than a problem with SoundManager, but I'm a noob at Javascript so am wondering if there are workarounds for this.

Cheers,
Stewart
1 person has
this problem
+1
Reply
  • Scott (Official Rep) August 31, 2010 04:26
    This is a weird one, which I attribute to the "magical" behaviour of the iPad (and Safari on the desktop) - where by "magical", I mean buggy and/or annoying. ;)

    From what I understand, the iPad and iPhone (iOS4 - currently 3.2 for iPad, 4.0 for iPhone) will not play a sequence of sounds unless a) the sound is initiated by the user eg., clicking a link leading to a play() call, and b) the second sound must be started from the onfinish() event of the first. With the first round of HTML5 audio support, this did not work in SM2 as I hadn't sorted out the iPhone/iPad behaviour - but "chaining" should work as of the 20100822 version, eg. the "Muxtape-style" demos on the homepage will play in sequence without further "clicking" after the first item has been tapped.

    It may be with the iPad that the "short sounds" issue exists; I have not thoroughly tested this, but desktop Safari is known to have some problems. I have seen weird looping issues with the "bc quail" test sound on the SM2 homepage using the iPad as well, which I'm at a loss to explain. I suspect it's another bug.

    Apple are aware of the issues with desktop Safari, and there are problems with loading sounds in general on the desktop under Snow Leopard, specifically (ironically, Safari on Windows seems to be OK.) More detail can be found with bugs.webkit.org #32159 if you're interested.

    Unfortunately the issue lies primarily with Apple at this time to the best of my knowledge; I'm hoping a software/firmware update will fix these things in the near future.
    • Hi Scott,

      Thanks for the reply. Something is definitely wrong with the iPad implementation. I persevered a bit with SoundManager and it eventually degraded to the point where I could play no sounds at all. The browser kept popping up a message like "Cannot play movie file" every time - even after clearing caches, rebooting the machine, etc. Following some advice I found elsewhere I did a "Reset All Settings" and the problems magically disappeared. It looks like it works providing you reload the sound on each play, which SoundManager currently does. Otherwise, it does seem to "drop" plays as described. I hope Apple will fix this in next next update to the iPad OS.

      Cheers,
      Stewart
    • Testing with a sound several seconds in length, I have not seen any "immediate" issues (maybe upwards of 60 plays on the iPhone/iOS 4 it errored out once, and then continued OK) - I'll try with some shorter sounds and see what happens. At this point I'm not seeing anything that would indicate resource exhaustion, however - which is a good thing.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. indifferent, undecided, unconcerned happy, confident, thankful, excited kidding, amused, unsure, silly sad, anxious, confused, frustrated

  • After playing a lot of sounds, starting on the iPad/iPhone via onclick handler and then using onfinish() to create and play the same sound with a unique URL, eg. 'foo.mp3?rnd='+Math.random() (and not unloading the old one), I was able to get the iPad and iPhone to eventually screw up - but not until loading and playing a 1-second MP3 close to 150 times in the iPad case. The iPad eventually showed "cannot play movie file" and needed a reboot to be fixed, but the iPhone did not crap out with the alert dialog, and seemed to be OK after a reload of the test page rather than a total power cycle.

    Example video clip with more notes:
    http://www.flickr.com/photos/schill/4...

    I should add, this is with the dev branch of SM2 that does not unload sounds when they finish playing. I am also not destroying the sounds.

    While this isn't "ideal", 100-someodd plays is pretty reasonable for these mobile devices in any case, I think. If you have an example case that can quickly bring up these errors, it'd be interesting to hear your findings for comparison. Maybe larger files or reusing sound objects are more problematic, etc.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. indifferent, undecided, unconcerned happy, confident, thankful, excited kidding, amused, unsure, silly sad, anxious, confused, frustrated