views:

303

answers:

2

I know that Apple's docs say that an mp3 within an <audio> tag on iPhone OS can't be played without user intervention (they cite bandwidth concerns, totally reasonable). However, has anyone succeeded in faking a user action to play the audio? Perhaps faking events to off screen native audio controls with JavaScript? I'm using jPlayer right now which works great on desktop Safari, but is silent on my iPad.

I'm prototyping a touch interface using WebKit on the iPad, and audio is an integral part of the experience, so yes, I do have a good reason to want to override this convention.

I'd appreciate any help. Thanks.

+1  A: 

what about user initiated playlists?

let the market decide. if you "aggravate user concerns" you will have no users.

I don't need apple defining what I can and cannot do as a developer.

Without javascript initiated audio events, you really cannot build a good music player (never mind all of the other scenarios that apple and I haven't considered)

candytunes.com
+3  A: 

I had this same problem ... wanting to be in control of the playback of sound from the "get go" as it were.

My solution was to put the audio tags in a hidden DIV like this.

<div id="junk" style="display: none">
  <audio id="effect1" src="..." autobuffer="autobuffer" controls="" ></audio>
  <audio id="effect2" src="..." autobuffer="autobuffer" controls="" ></audio>
  <audio id="effect3" src="..." autobuffer="autobuffer" controls="" ></audio>
</div>

Then in my javascript I have code like this in a play routine.

function playEffect(x) {
  var a = document.getElementById('effect' + x);
  if (a && a instanceof Audio) {
    if (a.currentTime) { a.currentTime = 0; }
    a.play();
  }
}

So ... you follow the rules because the "required" UI Control is there but of course it doesn't interfere with the web page. The check for currentTime in the playEffect function "rewinds" the sound ... if you don't do that, it won't play a second time.

This worked for me on iPad and iPhone as well as Safari on my Mac. I haven't tested IE for compliance. My page was integrated with Google Maps API v3.

I'll have to give this a shot.
Alex Ford