javascript - Play sound in iPhone web app - Stack Overflow

I assume there might be a HTML5 or some JS that can be used to play sound?Before you mark this as dupli

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?

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?

Share Improve this question edited May 23, 2017 at 12:02 CommunityBot 11 silver badge asked Oct 6, 2010 at 10:31 Alec SmartAlec Smart 96.1k39 gold badges124 silver badges186 bronze badges 1
  • stackoverflow./questions/1933969/… – pop850 Commented Oct 17, 2010 at 14:35
Add a ment  | 

3 Answers 3

Reset to default 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.

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.

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744989811a4604834.html

相关推荐

  • javascript - Play sound in iPhone web app - Stack Overflow

    I assume there might be a HTML5 or some JS that can be used to play sound?Before you mark this as dupli

    19小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信