如何在声音管理器中返回歌曲持续时间

发布于 2024-12-01 06:48:45 字数 481 浏览 0 评论 0原文

如何使用函数返回声音管理器中的歌曲持续时间?

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();

}

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

How can i return song duration in soundmanager with function ?

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();

}

This is my try, but it's not working

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

避讳 2024-12-08 06:48:45

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);
        }
    }
});

return is a keyword, not a variable. return this.duration; is what you'd want; skip the = (which will just give you a syntax error)

… but that won't help much, because where are you returning it to? You'll need to call another function, that does something with the duration. The item_duration function returns immediately after calling createSound, which then loads the file asynchronously

Try something like this

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);
        }
    }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文