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 に答える