Contents

AudioPlaybackGroupController

A controller that manages synchronized playback for a group of audio resources.

Declaration

@MainActor @preconcurrency class AudioPlaybackGroupController

Overview

You obtain an audio playback group controller by calling prepareAudio(_:) or playAudio(_:) with multiple AudioResource/Entity pairs. The controller coordinates all sources so they remain synchronized through playback, pause, seek, and rate changes.

Each source plays from its associated entity, so RealityKit applies that entity’s spatial audio characteristics independently. The same entity may appear multiple times with different resources, and a single entity can participate in multiple groups simultaneously.

// Load multiple audio resources.
let drums = try AudioFileResource.load(named: "Drums")
let bass  = try AudioFileResource.load(named: "Bass")
let lead  = try AudioFileResource.load(named: "Lead")

// Pair each resource with the entity that should emit it.
let pairs: [(AudioResource, Entity)] = [
    (drums, drumsEntity),
    (bass,  bassEntity),
    (lead,  leadEntity),
]

// Prepare and start synchronized playback.
let controller = try Audio.playAudio(pairs)

// Adjust the whole group together.
controller.fade(to: -6, duration: 0.5)

Use play(at:) to schedule a synchronized start at a future AVAudioTime, which is useful for aligning a group with other audio sources or external clocks.

To be notified when the group finishes playing, subscribe to AudioEvents.PlaybackGroupCompleted on the scene. The event fires once when playback reaches the end of the group’s audio stream.

Topics

Controlling playback

Accessing playback state

Instance Properties

Instance Methods

See Also

Acoustics and group playback