Calling getDurationMs on an AdvancedAudioPlayer instance always returns 0 before hitting play. Also, calling setPosition doesn't work, which makes sense since the song has 0 ms of duration.
After playing for the first time, the duration gets filled with a proper value, and setPosition works as expected.
Some code:
// Initialization
this.player = new Superpowered.AdvancedAudioPlayer(
samplerate,
2,
2,
0,
0.501,
2,
false
)
// When the track is loaded
this.player.openMemory(Superpowered.arrayBufferToWASM(buffer), false, false)
// When the UI thread asks for the duration
this.sendMessageToMainScope({
data: { duration: this.player.getDurationMs() },
})
After calling this.player.play(), this.player.getDurationMs() starts to give the correct duration value.
Is there an explanation for that? Is there any workaround?
I could get the correct duration by using Superpowered.Decoder, but having this information is useless because setPosition doesn't work.
You can only access these values after loading the track, which means playing it. A workaround would be to play the track and instantly pause it to get those values.