我们如何在soundamanager2中循环播放相同的音频文件?
这是我的示例代码
function playSound(url) {
soundManager.setup({
url: 'swf',
onready: function() {
soundManager.createSound({
id: 'samplesound',
url: url,
volume: 100
});
soundManager.play('samplesound');
}
});
}
从像
这样的标签中调用它<a href='javascrit:void(0);' onclick='playSound('url');'></a>
任何人都可以指导我连续循环这个声音吗?
感谢您的帮助...
答案 0 :(得分:3)
您可以使用播放命令
循环播放声音以下应播放声音3次
soundManager.play('samplesound',{loops: 3});
让循环工作的黑客可能是
var loops = 3;
var looped = 0;
soundManager.createSound({
id: 'samplesound',
url: url,
volume: 100,
onfinish:function() {
if(looped<loops){
soundManager.play('samplesound');
looped++;
} else{
looped = 0;
}
)}
});
见
http://www.schillmania.com/projects/soundmanager2/demo/api/
和
http://www.schillmania.com/projects/soundmanager2/doc/#smsoundmethods
答案 1 :(得分:1)
使用此实用程序功能:
function loopSound(sound, times) {
var current = 0;
_loopSound(sound, times, current);
function _loopSound(sound, times, current) {
if (++current <= times) {
sound.play({
onfinish : function() {
_loopSound(sound, times, current);
}
});
}
}
}
var mySound= soundManager.createSound({
url: '/mySound.mp3'
});
loopSound(mySound, 3);
答案 2 :(得分:0)
要设置默认选项“loop:1”,每次只播放一次声音。在我的网站中,Loop:2会一遍又一遍地播放。在他们的演示页面上,他们将其循环“循环:3”
soundManager.defaultOptions = {
loops: 2
};
答案 3 :(得分:0)
这对我有用:
soundManager.play('mysound', { loops: Infinity });