Play audio
To play an imported sound wave, use the same functions as you would for a regular one. For instance, use the PlaySound2D
or Play
function from an audio component such as Sound Cue.
To rewind the playback time of the sound wave, use the RewindPlaybackTime
function.
Additionally, in UE versions up to 4.27, if you want to start playback from a specific time greater than 0, you must use the RewindPlaybackTime
function beforehand. Otherwise, the sound may not play back correctly due to internal engine issues handling procedural waves. This issue has been resolved in the engine since version 5.0.
To get the current playing time of the sound wave, use the GetPlaybackTime
or GetPlaybackPercentage
functions. You can also obtain the duration of the sound wave by using the GetDuration
function.
To determine whether the sound wave is currently playing, you can use the IsPlaying
function.
To check if the sound wave has finished playing, you can use the IsPlaybackFinished
function.
You can stop the sound wave playback by using the StopPlayback
function. Please note that it is recommended to stop the sound wave playback using external means (e.g., by calling Stop on the audio component) and to use this function only if external means are not available.
Also, take in mind that this function does not work for playback from MetaSounds.
To track the end of audio playback, bind to the OnAudioPlaybackFinished
delegate.
You can manually clear the audio data using the ReleaseMemory
function. It is not recommended to do manually, but it can be useful if you have disabled the garbage collector.