SoundManager2:如何附加当前播放声音的onfinish事件回调

时间:2014-04-08 11:46:06

标签: javascript html5 soundmanager2

我在HTML中使用带有'ui360 / threeSixtyPlayer'样式的 SoundManager2 。 我有一个表和一系列锚点,其中相应的href设置为音频流。

当页面呈现时,我看到一系列播放按钮。 现在,用户可以选择其中任何一个播放声音,我没有对声音的引用 正在播放。

我需要一个onfinish event,以便我可以更新已完成播放的当前行的某些状态。

有没有办法将onfinish event附加到当前播放的声音中? 有人可以帮助我吗?

2 个答案:

答案 0 :(得分:0)

我不知道你在问这里之前是否检查过soundmanager文档,但我认为这看起来非常符合你的需要:

http://www.schillmania.com/projects/soundmanager2/doc/#sound-object-properties

答案 1 :(得分:0)

您必须在创建声音时附加onfinish处理程序:

var obj = soundManager.createSound({
    id: hash,
    url: '/any/url/file.mp3',
    //autoLoad: FlashDetect.installed,
    autoLoad:false, // Best response in HTML5
    volume: 10,
    autoPlay: true,
    stream: true,
    onfinish: function() {
        console.log('onfinish'); 
        // your on finish action here
    },
    onconnect: function() { 
        console.log('onconnect'); 
    },
    onload: function() {
        console.log('onload'); 
    }
    // etc
}

// This fires file.mp3, when it finishes playing will fire onfinish() 
obj.play()

有关更多处理程序和其他声音实例方法,请查看docs