I’m trying to pause a sound and then resume it after a certain time (changes dynamically). How could I do this in Blueprints? I know I can play from a time and stop it, but I want to pause and resume.
I’m afraid there isn’t currently a way of achieving this via Blueprints, I could help you out with a C++ approach if that’s something you could use.
I’ve added a TTP (#339865) to add this feature as it does seem like something that could be useful and asked for again.
Yes please, I’m quite capable of using C++ (just not for the project I’m currently working on), any help would be appreciated. Thanks.
Okay, I posted pretty much the same thing in answer to this forum thread the other day: Custom Music Player - C++ - Epic Developer Community Forums
You can use FAudioDevice::FindActiveSound to get the FActiveSound associated with the audio component while it’s playing. Then you’d have to use the map of FWaveInstances the active sound has (should only be one when playing a sound wave) and use the Audio Devices WaveInstanceSourceMap to get the sound source associated with it.
You can pause a Sound Source though there is one caveat in that if you pause and unpause the game, FAudioDevice::HandlePause will currently restart all sounds unless they are tagged with bIsUISound. I don’t know if setting your sound to be a UI Sound is an acceptable way to work around this issue for now.
If pause is eventually exposed to Blueprints we will have to add a way to differentiate between manually paused sounds and those paused by the game.
I know this is an old post, but I’m posting my method in case someone stumbles across this question. I did a very simple blueprint logic (and probably inefficient, but works for me.) I track the time the sound plays by a variable, let’s assume MusicPlayedFor.
This is initially set to 0 at the beginning.
Whenever my sound starts playing, I set the time by Get Audio Time Seconds
into a variable, let’s say MusicStartedAt.
Whenever it ‘pauses’ (in my case, by player input), it actually Stop
s and set another variable MusicPausedAt
by the Get Audio Time Seconds
.
Subtracting: MusicPausedAt
- MusicStartedAt
gives the time the current chunk of sound played.
Adding: MusicStartedAt
= MusicStartedAt
+ ( MusicPausedAt
- MusicStartedAt
) gives the time from the start of the sound till the pause action.
Then, when the next time Play
is hit, simply pipe this time into the Start Time
pin of the Play
node. Sound will start playing from where it left off.
All this higgedly-piggely will be unnecessary once the devs simply expose a stupid pause node. Till then, I’m sticking to this solution. Comments and criticisms are welcome!