问题在iPhone上玩soundclips与HTML5音频 [英] issues playing soundclips with HTML5 Audio on iPhone

查看:111
本文介绍了问题在iPhone上玩soundclips与HTML5音频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个MP3 soundclips在我的HTML5应用程序的特定事件的发挥。没有标签,脚本在开始(每个MP3)创建音频对象和加载的文件。当我有播放声音,我只是对这些对象之一调用play()。

I have a few mp3 soundclips to play at certain events on my HTML5 app. There's no tag, the script creates Audio objects at the beginning (one for each mp3) and loads the files. When I have to play a sound, I simply call play() on one of these objects.

这在Chrome桌面工作正常,但在我的iPod touch很不一致,最终一些声音停止播放,我甚至得到错误警报。

This works fine in a Chrome desktop, but is very inconsistent in my iPod touch, eventually some sounds stop playing and I even get error alerts.

下面是一个小的脚本,我成立了,看问题,它在 soundtest.staticloud.com 包括托管3音频文件,这样你就可以检查出来在iPhone /不管。

Here's a small script I set up to see the problem, it's hosted at soundtest.staticloud.com including the 3 audio files so you can check it out on an iPhone/whatever.

var snd = [];

window.onload = function() {
    for(var i = 0; i < 3; i++) {
        snd[i] = new Audio("snd" + i + ".mp3");
        snd[i].load();
    }
}

function sound(n) {
    snd[n-1].play();
}

我是不是做错了什么?

Am I doing something wrong?

推荐答案

我在的iDevices一吨的音频问题......你所要做的就是一片空白开始下一前的最后播放的剪辑。另外,我刚刚有了一个单一的音频对象,将改变来源,所以我的解决方案看起来更像是这样的:

I had a ton of audio problems in iDevices...what you have to do is blank out the last played clip before starting the next. Also, I just had a single audio object, and would change the source, so my solution looked more like this:

<html>
<body>
<audio></audio>
etc
</body>
<script type="text/javascript">
var sounds=[];

window.onload = function() {
    for(var i = 0; i < 3; i++) {
        sounds[i] = "snd" + i + ".mp3";
    }
}

function sound(n){
snd=document.getElementsByTagName("audio")[0];
snd.pause();  //-----------------PAUSE THE LAST (WHICH MAY BE LONG DONE)
snd.src='';   //-----------------BLANK SRC
snd.src=sounds[n-1];  //---------REPLACE WITH NEW SOUND
snd.load();
snd.play();
}
</script>
</html>

这篇关于问题在iPhone上玩soundclips与HTML5音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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