SoundEffectPool


class SoundEffectPool : 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 companion functions

SoundEffectPool
create(session: Session, maxStreams: Int)

Creates a SoundEffectPool with the given session and maxStreams.

Public functions

Unit

Adds a listener to be invoked when sounds finish loading.

Unit

Adds a listener to be invoked when sounds finish loading.

open Unit
SoundEffect
load(assetFileDescriptor: AssetFileDescriptor)

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

SoundEffect
load(context: Context, resId: Int)

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

Unit

Releases all native resources associated with this pool.

Unit

Removes a listener previously added via addLoadCompleteListener

Boolean
unload(soundEffect: SoundEffect)

Unloads a sound from memory to release resources.

Public companion functions

create

Added in 1.0.0-alpha15
fun create(session: Session, maxStreams: Int): SoundEffectPool

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
session: Session

the XR session associated with this sound effect pool

maxStreams: Int

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

Public functions

addLoadCompleteListener

Added in 1.0.0-alpha15
fun addLoadCompleteListener(listener: SoundEffectPool.LoadCompleteListener): Unit

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
fun addLoadCompleteListener(
    executor: Executor,
    listener: SoundEffectPool.LoadCompleteListener
): Unit

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

Parameters
executor: Executor

The Executor to run the listener on.

listener: SoundEffectPool.LoadCompleteListener

The LoadCompleteListener to be invoked asynchronously on the given executor.

close

Added in 1.0.0-alpha15
open fun close(): Unit

load

Added in 1.0.0-alpha15
fun load(assetFileDescriptor: AssetFileDescriptor): SoundEffect

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
assetFileDescriptor: AssetFileDescriptor

the AssetFileDescriptor for the sound file

Returns
SoundEffect

a SoundEffect handle for the loaded sound

load

Added in 1.0.0-alpha15
fun load(context: Context, resId: Int): SoundEffect

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
context: Context

the application context

resId: Int

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

Returns
SoundEffect

a SoundEffect handle for the loaded sound

release

Added in 1.0.0-alpha15
fun release(): Unit

Releases all native resources associated with this pool.

removeLoadCompleteListener

Added in 1.0.0-alpha15
fun removeLoadCompleteListener(
    listener: SoundEffectPool.LoadCompleteListener
): Unit

Removes a listener previously added via addLoadCompleteListener

unload

Added in 1.0.0-alpha15
fun unload(soundEffect: SoundEffect): Boolean

Unloads a sound from memory to release resources.

Parameters
soundEffect: SoundEffect

the SoundEffect to unload

Returns
Boolean

true if the sound was successfully unloaded