How to return duration soundmanager2
I'm using.
function item_duration(link,name) {
soundManager.createSound({
id: ''+name+'',
url: ''+link+'',
volume: 100,
autoLoad: true,
onload: function(){
if (this.readyState == 3) {
return this.duration;
}
}
});
//sound_duration.load();
//sound_duration.stop();
// soundManager.unload(''+name+'');
}
But it is not returning the duration it gives me 0, i tried to alert the duration and there is not 0 the alert shows different, but it takes time before开发者_开发百科 the alert appear.I don't thing that is the problem because i have statement .
You can get the duration by simply accessing the duration attribute of SoundManager object.
function getDuration()
{
var soundFile = {};
soundFile.id = 'aSound';
soundFile.url = '/tech/js/sound/s.mp3';
var mySound = soundManager.createSound(soundFile);
return mySound.duration;
}
check this:
soundManger.play('idSound',{
whileplaying: function(){
console.log(this.duration);
}
});
精彩评论