5

I assume there might be a HTML5 or some JS that can be used to play sound?

Before you mark this as duplicate, this question is old, so I believe outdated:

Play sound in iPhone web app with Javascript?

Community
  • 1
  • 1
Alec Smart
  • 94,115
  • 39
  • 120
  • 184
  • http://stackoverflow.com/questions/1933969/sound-effects-in-javascript-html5/1934325#1934325 – pop850 Oct 17 '10 at 14:35

3 Answers3

1

Maybe you could use a JS event, send a event to your UIWebView delegate and then play a sound with in objective-c ?

Best solution I think ^^

For a solution in HTML5 I have no idea. You could take a look at Sound effects in JavaScript / HTML5

But I'm not sure this solution would work on all device. It depends if you need to play the sound "often" or not.

Community
  • 1
  • 1
Vinzius
  • 2,890
  • 2
  • 26
  • 27
0

If noticed some issues in Chrome but otherwise seems to work in other major browsers.

HTML:

<audio id="sound_example" title="Sample" autobuffer>
  <source src="sample1.wav" type="audio/x-wav">
  <source src="sample2.ogg" type="application/ogg">
  <source src="sample3.mp3" type="audio/mpeg">
</audio>

Javascript:

var playThis = document.getElementById("sound_example");
if (!playThis.paused) {
    playThis.pause();
    playThis.currentTime = 0.0;
}
tmpAudio.play();

Obviously you'll need to provide your own wav, ogg, or mp3 to try this yourself. The check for it being paused is there so if the condition is met, it will reset before playing it again.

If you'd like to skip the audio tag altogether you can go with this:

var sound_example = new Audio("sample3.mp3");
sound_example.play();

There are some minor pros and cons to both approaches but if you're needs are straight-forward then either should suffice.

donohoe
  • 13,867
  • 4
  • 37
  • 59
0

The current version of mobile Safari (iOS 5.0.1) has poor audio HTML5 support. The play method of an Audio object will work sporadically, but only as the result of direct user click and it will not preload (expect a random delay on first play.) This makes it impractical to use audio in your iPhone web applications at this time.

Chris Broski
  • 2,421
  • 27
  • 23