Audio¶
Play sounds, control audio sources, and manage video playback through configurable actions.
Instead of writing playback scripts, you compose audio and video behaviors from modular actions in the Inspector. Need to play a clip, adjust volume, and enable looping? Add those operations to a single command and toggle each one on or off. Need to wait for a sound to finish before the next step? Use the play process. Everything works with both AudioSource and VideoPlayer components.
Assembly: Jungle.Audio
Dependencies: Jungle.Core, Jungle.Objects
Namespace: Jungle.Audio, Jungle.Audio.GameDev
AudioSource Command¶
The AudioSource Command lets you batch multiple audio operations into one action. Pick an AudioSource target, then toggle on the operations you need - play, set clip, adjust volume, and more - all in one Inspector entry.
Technically, this is AudioSourceCommand, a targeted command that executes a configurable list of audio actions:
[SerializeReference]
[JungleClassSelection]
private ICommand audioCommand = new AudioSourceCommand();
Available Actions¶
Each action appears as a toggleable entry in the Inspector (they implement IAudioSourceAction):
| Action | Description |
|---|---|
| Play | Play, Stop, Pause, or UnPause the source. Use the PlaybackMode enum to pick the operation. |
| Set Clip | Assigns an AudioClip to the source. Uses an IAudioClipValue provider so the clip can come from a direct reference, a ScriptableObject asset, or any other value source. |
| Set Volume | Sets audioSource.volume via a float pipeline (target value + modifier chain). |
| Set Pitch | Sets audioSource.pitch via a float pipeline. Values above 1 speed up playback; below 1 slow it down. |
| Set Spatial Blend | Sets audioSource.spatialBlend via a float pipeline. 0 = fully 2D, 1 = fully 3D. |
| Set Loop | Enable, Disable, or Toggle looping. |
| Set Mute | Mute, Unmute, or Toggle mute. Muting preserves playback position unlike Stop. |
Pipeline Actions (Volume, Pitch, Spatial Blend)¶
SetVolume, SetPitch, and SetSpatialBlend extend ValuePipelineCommand<float>, which means they support the full modifier chain. You can clamp, remap, ease, or otherwise shape the value before it reaches the AudioSource property.
Play Audio Command¶
PlayAudioCommand is a fire-and-forget command that calls PlayOneShot on one or more AudioSources. Use it for UI clicks, hit sounds, or any instant sound effect.
- Targets an
IAudioSourceValue(supports multiple sources) - Takes a direct
AudioClipreference - Does not wait for the clip to finish
Play Audio Process¶
PlayAudioProcess implements IProcess and stays alive until the clip finishes playing. Use it in sequences where the next step should wait for the sound to complete.
| Property | Behavior |
|---|---|
Duration |
Returns the clip length in seconds (0 if no clip). |
Begin() |
Plays the clip via PlayOneShot and schedules completion after clip.length. |
Complete() |
Stops all sources immediately and cancels the pending timer. |
SupportsPause |
false — pause is not supported since PlayOneShot cannot be paused. |
Video Player Command¶
VideoPlayerCommand works the same way as AudioSourceCommand but targets a Unity VideoPlayer. Actions are composed from IVideoAction implementations in a toggle-set.
[SerializeReference]
[JungleClassSelection]
private ICommand videoCommand = new VideoPlayerCommand();
Available Video Actions¶
| Action | Description |
|---|---|
| Play | Starts or resumes video playback. |
| Pause | Pauses playback. |
| Stop | Stops playback and resets to the beginning. |
| Set Clip | Assigns a VideoClip to the player. |
| Set Loop | Enables or disables video looping. |
| Set Playback Speed | Sets the speed multiplier (1.0 = normal). |
Value Providers¶
Jungle.Audio defines value interfaces and providers for audio-related types, following the standard Jungle values pattern.
AudioSource Values¶
| Type | Description |
|---|---|
IAudioSourceValue |
Interface for providing an AudioSource reference. |
AudioSourceValue |
Inline reference stored directly on the component. (default) |
AudioSourceValueAsset |
ScriptableObject — create via Assets > Create > Jungle > Audio > AudioSource Value. |
AudioSourceValueFromAsset |
Reads from an AudioSourceValueAsset. |
AudioSourceListValueAsset |
ScriptableObject storing a list of AudioSources. |
AudioClip Values¶
| Type | Description |
|---|---|
IAudioClipValue |
Interface for providing an AudioClip reference. |
AudioClipValue |
Inline reference stored directly on the component. (default) |
AudioClipValueAsset |
ScriptableObject — create via Assets > Create > Jungle > Audio > AudioClip Value. |
AudioClipValueFromAsset |
Reads from an AudioClipValueAsset. |
AudioClipListValueAsset |
ScriptableObject storing a list of AudioClips. |
Video Values¶
| Type | Description |
|---|---|
IVideoPlayerValue |
Interface for providing a VideoPlayer reference. |
VideoPlayerValue |
Inline reference stored directly on the component. (default) |
IVideoClipValue |
Interface for providing a VideoClip reference. |
VideoClipValue |
Inline reference stored directly on the component. |
Usage Examples¶
Play a sound effect on an event¶
Attach a CommandRunner (or any process launcher) and assign a PlayAudioCommand:
// On a MonoBehaviour with a CommandRunner or event listener
[SerializeReference]
[JungleClassSelection]
private ICommand onHitSound = new PlayAudioCommand();
Configure the AudioSource and clip in the Inspector. The command fires once and forgets.
Compose multiple audio operations¶
Use AudioSourceCommand to set volume, assign a clip, and play — all in one command:
[SerializeReference]
[JungleClassSelection]
private ICommand setupAndPlay = new AudioSourceCommand(
new SetVolume(),
new SetClip(),
new Play()
);
In the Inspector, each action appears as a toggleable entry. Enable only what you need.
Wait for a sound to finish before continuing¶
Use PlayAudioProcess in a process sequence:
[SerializeReference]
[JungleClassSelection]
private IProcess introSound = new PlayAudioProcess();
// In a sequence, the next process begins only after the clip finishes.
Share an AudioSource across multiple components¶
Create an AudioSourceValueAsset via Assets > Create > Jungle > Audio > AudioSource Value, assign the AudioSource once, and reference the asset from any command:
[SerializeReference]
[JungleClassSelection]
private IAudioSourceValue source = new AudioSourceValueFromAsset();
This decouples the AudioSource reference from any single component.