2

我们如何在 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>

谁能指导我在各个时间连续循环这个声音??

谢谢您的帮助...

4

4 回答 4

3

您可以使用 play 命令循环播放声音

以下应播放声音 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

于 2013-03-17T19:52:58.507 回答
1

将默认选项设置为“loop:1”将只播放每个声音一次。在我的网站中,Loop: 2 会一遍又一遍地播放。在他们的演示页面上,他们循环播放“loops: 3”

soundManager.defaultOptions = {

 loops: 2

};
于 2014-02-15T14:04:13.533 回答
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);
于 2014-02-17T22:03:01.450 回答
0

这对我有用:

soundManager.play('mysound', { loops: Infinity });

于 2017-11-24T08:32:55.770 回答