Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/466.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在soundmanager中返回歌曲持续时间_Javascript_Soundmanager2 - Fatal编程技术网

Javascript 如何在soundmanager中返回歌曲持续时间

Javascript 如何在soundmanager中返回歌曲持续时间,javascript,soundmanager2,Javascript,Soundmanager2,如何在soundmanager中使用函数返回歌曲持续时间 function item_duration(){ var song_item = soundManager.createSound({ id:'etc', url:'etc', onload: function() { if(this.readyState == 'loaded' || this.rea

如何在soundmanager中使用函数返回歌曲持续时间

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

}

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

返回
是一个关键字,而不是一个变量<代码>返回此值。持续时间是您想要的;跳过
=
(这只会给你一个语法错误)

…但这不会有多大帮助,因为你要把它还给哪里?您将需要调用另一个函数,该函数在持续时间内执行某些操作。调用
createSound
后,函数会立即返回
item\u duration
,然后异步加载文件

试试这样的

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
是一个关键字,而不是变量<代码>返回此值。持续时间是您想要的;跳过
=
(这只会给你一个语法错误)

…但这不会有多大帮助,因为你要把它还给哪里?您将需要调用另一个函数,该函数在持续时间内执行某些操作。调用
createSound
后,函数会立即返回
item\u duration
,然后异步加载文件

试试这样的

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

我要开枪自杀,Axaxaxa是等号,天哪,我不知道该说什么,我知道如何使用return,等等。。哦。。不要说话。。因此,谢谢,你的代码不适合我的情况,但是,由于修复了该死的秋季错误,这在当前版本(2013年10月)中是不相关的。onload不是createSound选项的一部分。我要自杀了,axaaxaxa是一个等号,天哪,我不知道该说什么,我知道如何使用return,等等。。哦。。不要说话。。因此,谢谢,你的代码不适合我的情况,但是,由于修复了该死的秋季错误,这在当前版本(2013年10月)中是不相关的。onload不是createSound选项的一部分。