prepareAudio(_:)
Prepares an audio resource for playback.
Declaration
@MainActor @preconcurrency func prepareAudio(_ resource: AudioResource) -> AudioPlaybackControllerParameters
- resource:
The audio resource the method plays. Load an audio resource from the file system with Init(named:in:configuration:) , or from a URL with Init(contentsof:withname:configuration:).
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()