Anderberg Posted May 6, 2014 Share Posted May 6, 2014 I have a situation where I need to know the duration of my sound elements before they are played. However, the duration is 0 (as well as durationMS and totalDuration). So I dug into the code and realised that duration is only set if the browser uses the audio tag, not when it uses the webaudio api (latest chrome use the latter). So what is the best way to get the duration? I have done some digging:Using the game.cache.getSound(key) you can extract information about the sound object. This object will hold a "data" property which has a "duration" property. But this is only set once the audio file has been decoded. The preload in a state does not wait for audio files to be decoded, which means that in the beginning of the create-state this data might not be available (aka when I need it to be). Have anyone battled audio duration and succeeded? Link to comment Share on other sites More sharing options...
Anderberg Posted May 9, 2014 Author Share Posted May 9, 2014 I temporarily fixed this by putting the files I need decoded first on the top of the preload loader list. This does not seem like a bulletproof solution though... Link to comment Share on other sites More sharing options...
QLNEO Posted January 26, 2018 Share Posted January 26, 2018 This is a very old thread, but since it popped up on search (I'm having the same problem as OP but I'm pretty sure my sound is decoded <EDIT: That was solved as well >) I want to add that Sound.onDecoded sends a signal that you can use when you want to wait for a sound to be decoded. Not sure if that was available on the time this thread was made, but for anyone searching, this is a thing. samme 1 Link to comment Share on other sites More sharing options...
Recommended Posts