# SoundEffectPlayer

Artifact: [androidx.xr.scenecore:scenecore](https://developer.android.com/jetpack/androidx/releases/xr-scenecore) [View Source](https://cs.android.com/search?q=file:androidx/xr/scenecore/SoundEffectPlayer.kt+class:androidx.xr.scenecore.SoundEffectPlayer) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

*** ** * ** ***


```
public interface SoundEffectPlayer
```

<br />

Known direct subclasses [SoundEffectPoolComponent](https://developer.android.com/reference/androidx/xr/scenecore/SoundEffectPoolComponent)

|---|---|
| `https://developer.android.com/reference/androidx/xr/scenecore/SoundEffectPoolComponent` | Provides positional sound pool audio playback for an `https://developer.android.com/reference/androidx/xr/scenecore/Entity`. |

*** ** * ** ***

Provides playback control for instances of `https://developer.android.com/reference/androidx/xr/scenecore/SoundEffect`.

## Summary

| ### Public methods |
|---|---|
| `abstract void` | `https://developer.android.com/reference/androidx/xr/scenecore/SoundEffectPlayer#pause(androidx.xr.scenecore.Stream)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Stream stream)` Pauses a currently playing sound stream. |
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Stream` | `https://developer.android.com/reference/androidx/xr/scenecore/SoundEffectPlayer#play(androidx.xr.scenecore.SoundEffect,kotlin.Float,kotlin.Int,kotlin.Boolean)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/SoundEffect soundEffect, @https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0, to = 1.0) float volume, @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int priority, boolean isLooping )` Plays a loaded sound effect. |
| `abstract void` | `https://developer.android.com/reference/androidx/xr/scenecore/SoundEffectPlayer#resume(androidx.xr.scenecore.Stream)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Stream stream)` Resumes a previously paused sound stream. |
| `abstract void` | `https://developer.android.com/reference/androidx/xr/scenecore/SoundEffectPlayer#setLooping(androidx.xr.scenecore.Stream,kotlin.Boolean)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Stream stream, boolean isLooping)` Updates the looping status of an active stream. |
| `abstract void` | `https://developer.android.com/reference/androidx/xr/scenecore/SoundEffectPlayer#setVolume(androidx.xr.scenecore.Stream,kotlin.Float)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Stream stream, @https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0, to = 1.0) float volume )` Updates the volume of an active stream. |
| `abstract void` | `https://developer.android.com/reference/androidx/xr/scenecore/SoundEffectPlayer#stop(androidx.xr.scenecore.Stream)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Stream stream)` Stops a currently playing or paused sound stream and releases that stream ID. |

## Public methods

### pause

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

```
abstract void pause(@NonNull Stream stream)
```

Pauses a currently playing sound stream.

If the `https://developer.android.com/reference/androidx/xr/scenecore/SoundEffectPlayer#pause(androidx.xr.scenecore.Stream)` has already been stopped or released due to hitting the max stream count then this method has no effect.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Stream stream` | a `https://developer.android.com/reference/androidx/xr/scenecore/Stream` returned by `https://developer.android.com/reference/androidx/xr/scenecore/SoundEffectPlayer#play(androidx.xr.scenecore.SoundEffect,kotlin.Float,kotlin.Int,kotlin.Boolean)` |

### play

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

```
abstract @NonNull Stream play(
    @NonNull SoundEffect soundEffect,
    @FloatRange(from = 0.0, to = 1.0) float volume,
    @IntRange(from = 0) int priority,
    boolean isLooping
)
```

Plays a loaded sound effect.

The `https://developer.android.com/reference/androidx/xr/scenecore/SoundEffect`s can play concurrently up to the max stream count of the `https://developer.android.com/reference/androidx/xr/scenecore/SoundEffectPool` from which they were loaded. If the max stream count is exceeded, streams with lower priority are stopped first.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/SoundEffect soundEffect` | the handle to the loaded `https://developer.android.com/reference/androidx/xr/scenecore/SoundEffect` to play |
| `@https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0, to = 1.0) float volume` | volume in the range 0.0 to 1.0 |
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int priority` | playback priority (0 = lowest) |
| `boolean isLooping` | true to loop indefinitely, false to play once |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Stream` | a `https://developer.android.com/reference/androidx/xr/scenecore/Stream` for controlling this specific instance of the sound |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-runtime-exception/index.html` | if the sound effect fails to play |

### resume

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

```
abstract void resume(@NonNull Stream stream)
```

Resumes a previously paused sound stream.

If the `https://developer.android.com/reference/androidx/xr/scenecore/SoundEffectPlayer#resume(androidx.xr.scenecore.Stream)` has already been stopped or released due to hitting the max stream count then this method has no effect.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Stream stream` | a `https://developer.android.com/reference/androidx/xr/scenecore/Stream` returned by `https://developer.android.com/reference/androidx/xr/scenecore/SoundEffectPlayer#play(androidx.xr.scenecore.SoundEffect,kotlin.Float,kotlin.Int,kotlin.Boolean)` |

### setLooping

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

```
abstract void setLooping(@NonNull Stream stream, boolean isLooping)
```

Updates the looping status of an active stream.

If the `https://developer.android.com/reference/androidx/xr/scenecore/SoundEffectPlayer#setLooping(androidx.xr.scenecore.Stream,kotlin.Boolean)` has already been stopped or released due to hitting the max stream count then this method has no effect.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Stream stream` | a `https://developer.android.com/reference/androidx/xr/scenecore/Stream` returned by `https://developer.android.com/reference/androidx/xr/scenecore/SoundEffectPlayer#play(androidx.xr.scenecore.SoundEffect,kotlin.Float,kotlin.Int,kotlin.Boolean)` |
| `boolean isLooping` | true to loop indefinitely, false to stop looping |

### setVolume

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

```
abstract void setVolume(
    @NonNull Stream stream,
    @FloatRange(from = 0.0, to = 1.0) float volume
)
```

Updates the volume of an active stream.

If the `https://developer.android.com/reference/androidx/xr/scenecore/SoundEffectPlayer#setVolume(androidx.xr.scenecore.Stream,kotlin.Float)` has already been stopped or released due to hitting the max stream count then this method has no effect.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Stream stream` | a `https://developer.android.com/reference/androidx/xr/scenecore/Stream` returned by `https://developer.android.com/reference/androidx/xr/scenecore/SoundEffectPlayer#play(androidx.xr.scenecore.SoundEffect,kotlin.Float,kotlin.Int,kotlin.Boolean)` |
| `@https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0, to = 1.0) float volume` | volume in the range 0.0 to 1.0 |

### stop

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

```
abstract void stop(@NonNull Stream stream)
```

Stops a currently playing or paused sound stream and releases that stream ID.

If the `https://developer.android.com/reference/androidx/xr/scenecore/SoundEffectPlayer#stop(androidx.xr.scenecore.Stream)` has already been stopped or released due to hitting the max stream count then this method has no effect.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Stream stream` | a `https://developer.android.com/reference/androidx/xr/scenecore/Stream` returned by `https://developer.android.com/reference/androidx/xr/scenecore/SoundEffectPlayer#play(androidx.xr.scenecore.SoundEffect,kotlin.Float,kotlin.Int,kotlin.Boolean)` |