Contents

prepareAudio(_:)

Prepares an audio resource for playback.

Declaration

@MainActor @preconcurrency func prepareAudio(_ resource: AudioResource) -> AudioPlaybackController

Parameters

Return Value

An AudioPlaybackController object that you can use to start and stop audio playback for this specific instance of a resource playing on this entity. You can also use this controller to update playback properties, such as gain and speed, during playback.

Discussion

To start playback right away with default AudioPlaybackController properties, use the playAudio(_:) method instead.

For optimal system resource usage, avoid preparing sounds before they are needed. For example:

let controller = entity.prepareAudio(anAudioResource)
controller.gain = -10 // Apply a custom gain, if desired.
controller.speed = 1.2 // Apply a custom speed, if desired.
controller.play()

See Also

Playing audio