1

如何使用功能在声音管理器中返回歌曲持续时间?

function item_duration(){
    var song_item = soundManager.createSound({
        id:'etc',
        url:'etc',
        onload: function() {
                    if(this.readyState == 'loaded' ||
                    this.readyState == 'complete' ||
                    this.readyState == 3){
                    return = this.duration;         
                    }
       }
   });

   song_item.load();

}

这是我的尝试,但它不起作用

4

1 回答 1

1

return是关键字,而不是变量。return this.duration;是你想要的;跳过=(只会给你一个语法错误)

……但这无济于事,因为你要把它归还到哪里你需要调用另一个函数,它对持续时间做一些事情。item_duration函数调用后立即返回,createSound然后异步加载文件

尝试这样的事情

function doSomethingWithTheSoundDuration(duration) {
    alert(duration); // using alert() as an example…
}

soundManager.createSound({
    id:  …,
    url: …,
    onload: function() {
        // no need to compare with anything but the number 3
        // since readyState is a number - not a string - and
        // 3 is the value for "load complete"
        if( this.readyState === 3 ) { 
            doSomethingWithTheSoundDuration(this.duration);
        }
    }
});
于 2011-08-24T21:10:15.227 回答