How to get current playback time/position of the sound playing on an audio component

How to get current playback time/position of the sound playing on an audio component?

Thanks!

2 Likes

You can do something like this:

As soon as the audio component starts playing, that callback will be fired off on every tick update for the sound. You can get the current position of the sound by multiplying its duration by the playback percent (playback percent is between 0 and 1).

7 Likes

It is in C++, but I believe that it is not directly accessible in Blueprints without being passed through that callback.

interesting, wondering why the playback position isn’t accessible…

How did you get the PlaybackPercent?
I can’t seem to access the percentage anywhere…
Thank you!

Have you tried what vedemag suggested?
Not quite sure, but I also heard them updating the audio engine, they might have new APIs for that.

Ah I found it! Works!
The blue “Audio” node can’t be anything but an AudioComponent.
Then you drag off that node to get the blue “Bind Event to OnAudioPlaybackPercent” node.
Then from that node you drag off the red pin and click create Custom Event. That’s how you end up with a Custom Event node that has the two outputs: “Playing Sound Wave” and “Playback Percent”.

Thanks guys!

2 Likes

Few WAV files are not able to do this. Is there a way to check what’s different between these WAV files?

#Play After Bind#

Because the audio thread is mulit threaded, you have to set the binding before you play the audio.

In Vedemag’s case (thank you for sharing Vedemag!), this works because the audio component was added to the actor itself.

In the case of Spawn Audio 2D for example, which does autoplay, you have to bind and then play again.

5 Likes

I tried vedemags example but it seems to return 0 upon restarting the engine I tried reimporting and that fixed it but once I built my project it went back to returning 0 any ideas?