PositionalAudioComponent


public final class PositionalAudioComponent extends Component


A Component that provides positional spatial audio playback for an Entity.

It provides an AudioOutputProvider which can be used to configure an androidx.media3.exoplayer.ExoPlayer.Builder instance for positional audio playback.

This component can only be attached to one Entity at a time. If the component is detached from an Entity, the audio will become head-locked.

Summary

Public methods

static final @NonNull PositionalAudioComponent

Creates a PositionalAudioComponent for the given session and initializes it with the provided params.

final @NonNull AudioOutputProvider

An AudioOutputProvider that can be used to configure an androidx.media3.exoplayer.ExoPlayer.Builder for positional audio playback.

final void

Updates the PointSourceParams used by the spatial audio source.

Protected methods

boolean

Called by the framework when this component is being added to an Entity.

void

Called by the framework when this component is being removed from an Entity.

Public methods

create

Added in 1.0.0-alpha15
public static final @NonNull PositionalAudioComponent create(@NonNull Session session, @NonNull PointSourceParams params)

Creates a PositionalAudioComponent for the given session and initializes it with the provided params.

getAudioOutputProvider

Added in 1.0.0-alpha15
public final @NonNull AudioOutputProvider getAudioOutputProvider()

An AudioOutputProvider that can be used to configure an androidx.media3.exoplayer.ExoPlayer.Builder for positional audio playback.

setPointSourceParams

Added in 1.0.0-alpha15
public final void setPointSourceParams(@NonNull PointSourceParams params)

Updates the PointSourceParams used by the spatial audio source.

These params will apply to currently playing audio and future playback requests.

Protected methods

onAttach

protected boolean onAttach(@NonNull Entity entity)

Called by the framework when this component is being added to an Entity.

This method is triggered when Entity.addComponent is invoked. Implementations should override this method to perform setup logic or to validate if the component is compatible with the provided entity.

Parameters
@NonNull Entity entity

The Entity to which this component is being attached.

Returns
boolean

true if the component was successfully attached; false if the entity does not support this component or if attachment failed.

onDetach

protected void onDetach(@NonNull Entity entity)

Called by the framework when this component is being removed from an Entity.

This method is triggered when Entity.removeComponent is invoked. Implementations should override this method to release resources or undo any changes made during onAttach.

Parameters
@NonNull Entity entity

The Entity from which this component is being detached.