Play sound in iPhone web app

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?

Answers


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.


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.


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.


Need Your Help

How can I get a SQL query to show one value if another value is empty/not existent

php mysql mariadb

I currently have a query and it gives me an error when I run it, the error is in this part:

C++ enum class quint64 type

c++ c++11 enums

I have following enum class: