I’m trying to get the actual duration of the sound file looped in a Sound Cue.
When I try to get this using the GetDuration function it works fine when using a non-looped sound but as soon as I tick the ‘Looping’ check box in the Sound Cue Editor and save, the duration jumps up to 10000.000000.
Is there a way to get the actual duration of the looped wave file itself? I’ve tried using a workaround by checking if the sound is playing and restarting it when it has stopped playing but it doesn’t loop seamlessly in that case.
In code we define INDEFINITELY_LOOPING_DURATION as 10000 to show that a sound will loop forever (and to ensure that anything using it literally won’t stop for a long time at least). Even in a non-looping SoundCue the duration can be a best guess, if there are random nodes involved or changes in pitch etc.
If you want to get the original duration of the sound file then you will need access to the SoundWave that you are using in the SoundCue (or just use a SoundWave instead of a cue if it is a simple sound loop). There you’ll want to check the Duration property (which is inherited from SoundBase). There is also a GetDuration function but this works just like the SoundCue, it returns INDEFINITELY_LOOPING_DURATION if the SoundWave’s Looping property is set.
If you do need to access the SoundWave from within the SoundCue, then I would advise using USoundCue::RecursiveFindNode like this:
// get all the waves this cue uses
Thanks, that did the trick. I’m using this to sync up multiple music tracks once they switch between one and another in our dynamic music system.