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

SoundManager2: How to attach a onfinish event callback of the current Playing sound

本文关键字:onfinish 事件 回调 播放声音 何附加 SoundManager2      更新时间:2023-09-26

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

当页面渲染时,我会看到一系列"播放"按钮。现在,用户可以选择其中的任何一个来播放声音,我没有声音的参考正在播放。

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

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

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

http://www.schillmania.com/projects/soundmanager2/doc/#sound-对象属性

您必须在创建声音时附加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()

有关更多处理程序和其他声音实例方法,请参阅文档。