如果在ajax成功函数上调用,声音将不会播放 [英] Sound won't play if invoked on ajax success function

查看:164
本文介绍了如果在ajax成功函数上调用,声音将不会播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的移动网页中嵌入了一个声音剪辑,如下所示:

I have a sound clip embedded in my mobile web page like so:

<audio id="sound">
<source src="/assets/sound/mysound.mp3" type="audio/mpeg">
</audio>

我这样称呼它:

$('#sound').get(0).play();

这在我的笔记本电脑和iPhone上都适用于Chrome.但是,如果我像这样在ajax的成功函数中调用它

This works fine on chrome in both my laptop and iPhone. However, if I call this within the success function of ajax like so

$.ajax({
    ....
    success: function() {
      $('#sound').get(0).play();
    }

在笔记本电脑的Chrome浏览器上,它可以正常工作.但是在iOS的chrome或safari中,没有声音播放.

On the chrome browser of my laptop, it works fine. But on chrome or safari in iOS, no sound is played.

还有其他人碰到这个吗?

Anyone else run into this?

推荐答案

iOS对何时/如何在Web应用程序中播放音频设置了一些限制.例如,您不能简单地自动播放声音,而是必须从用户事件(点击按钮等)中启动声音.

iOS places some restrictions on when/how you can play audio in web apps. For example, you can't simply auto-play sounds, but they have to be initiated from a user-event (tapping a button, etc).

查看更多信息: http://www.ibm.com/developerworks/library/wa-ioshtml5/#N100E8

这篇关于如果在ajax成功函数上调用,声音将不会播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆