SoundEffectPool


public final class SoundEffectPool implements AutoCloseable


Manages the loading and unloading of sound assets into memory.

If the value of the maxStreams parameter exceeds the capabilities for the platform then the value will be clamped to the platform's max number of supported streams.

Summary

Nested types

Callback interface for receiving notification when a sound effect has finished loading.

Public methods

final void

Adds a listener to be invoked when sounds finish loading.

final void

Adds a listener to be invoked when sounds finish loading.

void
static final @NonNull SoundEffectPool
create(@NonNull Session session, int maxStreams)

Creates a SoundEffectPool with the given session and maxStreams.

final @NonNull SoundEffect
load(@NonNull AssetFileDescriptor assetFileDescriptor)

Loads a sound from an AssetFileDescriptor and returns a SoundEffect handle.

final @NonNull SoundEffect
load(@NonNull Context context, int resId)

Loads a sound from an application resource and returns a SoundEffect handle.

final void

Releases all native resources associated with this pool.

final void

Removes a listener previously added via addLoadCompleteListener

final boolean
unload(@NonNull SoundEffect soundEffect)

Unloads a sound from memory to release resources.

Public methods

addLoadCompleteListener

Added in 1.0.0-alpha15
public final void addLoadCompleteListener(
    @NonNull SoundEffectPool.LoadCompleteListener listener
)

Adds a listener to be invoked when sounds finish loading. The listener will be called on the main thread.

addLoadCompleteListener

Added in 1.0.0-alpha15
public final void addLoadCompleteListener(
    @NonNull Executor executor,
    @NonNull SoundEffectPool.LoadCompleteListener listener
)

Adds a listener to be invoked when sounds finish loading. The listener will be called on the given Executor.

Parameters
@NonNull Executor executor

The Executor to run the listener on.

@NonNull SoundEffectPool.LoadCompleteListener listener

The LoadCompleteListener to be invoked asynchronously on the given executor.

close

Added in 1.0.0-alpha15
public void close()

create

Added in 1.0.0-alpha15
public static final @NonNull SoundEffectPool create(@NonNull Session session, int maxStreams)

Creates a SoundEffectPool with the given session and maxStreams.

If the value of the maxStreams parameter exceeds the capabilities for the platform then the value will be clamped to the platform's max number of supported streams.

Parameters
@NonNull Session session

the XR session associated with this sound effect pool

int maxStreams

maximum number of simultaneous streams that can be played by this pool

load

Added in 1.0.0-alpha15
public final @NonNull SoundEffect load(@NonNull AssetFileDescriptor assetFileDescriptor)

Loads a sound from an AssetFileDescriptor and returns a SoundEffect handle.

Note: Loading is asynchronous. The sound may not be ready to play immediately after this method returns. Use LoadCompleteListener to be notified when it is ready.

Parameters
@NonNull AssetFileDescriptor assetFileDescriptor

the AssetFileDescriptor for the sound file

Returns
@NonNull SoundEffect

a SoundEffect handle for the loaded sound

load

Added in 1.0.0-alpha15
public final @NonNull SoundEffect load(@NonNull Context context, int resId)

Loads a sound from an application resource and returns a SoundEffect handle.

Note: Loading is asynchronous. The sound may not be ready to play immediately after this method returns. Use LoadCompleteListener to be notified when it is ready.

Parameters
@NonNull Context context

the application context

int resId

resource ID of the sound (e.g., R.raw.sound)

Returns
@NonNull SoundEffect

a SoundEffect handle for the loaded sound

release

Added in 1.0.0-alpha15
public final void release()

Releases all native resources associated with this pool.

removeLoadCompleteListener

Added in 1.0.0-alpha15
public final void removeLoadCompleteListener(
    @NonNull SoundEffectPool.LoadCompleteListener listener
)

Removes a listener previously added via addLoadCompleteListener

unload

Added in 1.0.0-alpha15
public final boolean unload(@NonNull SoundEffect soundEffect)

Unloads a sound from memory to release resources.

Parameters
@NonNull SoundEffect soundEffect

the SoundEffect to unload

Returns
boolean

true if the sound was successfully unloaded