pizzicato
pizzicato copied to clipboard
sound.duration() needed
I am chaining together sounds and visual animations in a game. In order to run an animation "when a sound ends" I need to know the sound's duration.
I'd rather not hard-code that information. Is it possible to say
let someDuration = sound.duration()
PS I'm converting from howlerjs and that code does provide the sound duration, though it is not clear to me how the achieve it.
Hi Ken,
Check the sound object's source node. sound.sourceNode.buffer.duration
Michael
When I console.log(sound)
I can see the sound.sourceNode
property but I console.log(sound.sourceNode)
I get undefined
. Strange...
console.log(sound.__proto__)
reveals some insight:
addEffect: function(e2)
applyAttack: function()
clone: function()
connect: function(e2)
connectEffects: function()
disconnect: function(e2)
frequency:
getInputNode: function()
getSourceNode: function() // <-
onEnded: function(e2)
pause: function()
play: function(e2, t2)
removeEffect: function(e2)
stop: function()
stopWithRelease: function(e2)
sustain:
volume:
@types/pizzicato
is unaware of this sound.getSourceNode()
function, but indeed it exists and it does return the underlying source node. I had to do this:
sound.getSourceNode().buffer.duration
// => ...