Skip to content

Instantly share code, notes, and snippets.

@eospi
Last active June 5, 2021 01:53
Show Gist options
  • Save eospi/e30a2711d38b6aea99ab6abf3a10eab7 to your computer and use it in GitHub Desktop.
Save eospi/e30a2711d38b6aea99ab6abf3a10eab7 to your computer and use it in GitHub Desktop.
let audioFilePath = "path/to/audio/file"
let entity = Entity()
do {
let resource = try AudioFileResource.load(named: audioFilePath, in: nil, inputMode: .spatial, loadingStrategy: .preload, shouldLoop: true)
let audioController = entity.prepareAudio(resource)
audioController.play()
// If you want to start playing right away, you can replace lines 7-8 with line 11 below
// let audioController = entity.playAudio(resource)
} catch {
print("Error loading audio file")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment