Skip to content

Audio

Play sounds, control audio sources, and manage video playback through configurable operations.

Instead of writing playback scripts, you compose audio and video behaviors from modular operations 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 audio operation. 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 process. 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 (TargetedCommand<AudioSource, IAudioOperation>) that executes a configurable list of audio operations in parallel:

[SerializeReference]
[JungleClassSelection]
private IProcess audioCommand = new AudioSourceCommand();

Available Operations

Each operation appears as a toggleable entry in the Inspector (they implement IAudioOperation):

Operation 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.

Instant vs Timed Operations

Operations fall into two categories:

  • Instant operations extend InstantAudioOperation and complete immediately (Play, Set Clip, Set Loop, Set Mute). They override Execute(AudioSource) and the base handles the IAudioOperation plumbing.
  • Timed operations implement IAudioOperation directly and self-tick until finished. PlayAudioOperation plays a clip and completes when it ends. AudioFloatPipelineOperation drives a float property (volume, pitch, or spatial blend) over time using the pipeline pattern with targets, modifiers, and a completion check.

The command runs all operations in parallel and completes when every operation has finished.

Pipeline Operations (Volume, Pitch, Spatial Blend Over Time)

AudioFloatPipelineOperation can drive volume, pitch, or spatial blend over time using the pipeline pattern: target + modifier chain + completion check. Select which AudioFloatProperty to drive, configure an IFloatTarget for the desired curve, and add optional IFloatModifier entries for smoothing or clamping.

For instant one-shot changes, SetVolume, SetPitch, and SetSpatialBlend extend InstantAudioOperation and write the value immediately.


Play Audio Operation

PlayAudioOperation is a timed audio operation that plays a clip via PlayOneShot and stays alive until the clip finishes. Use it inside an AudioSourceCommand when the next step should wait for playback to end.

Property Behavior
IsComplete Returns true once the clip has finished playing (or immediately if no clip is set).
Begin() Plays the clip via PlayOneShot and schedules completion after clip.length.
Complete() Stops the source immediately and cancels the pending timer.
Pause() Pauses the AudioSource.
Unpause() Resumes the AudioSource.

Video Player Command

VideoPlayerCommand works the same way as AudioSourceCommand but targets a Unity VideoPlayer. Operations are composed from IVideoOperation implementations in a toggle-set. It follows the TargetedCommand<VideoPlayer, IVideoOperation> pattern.

[SerializeReference]
[JungleClassSelection]
private IProcess videoCommand = new VideoPlayerCommand();

Available Video Operations

Operation 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

Compose multiple audio operations

Use AudioSourceCommand to set volume, assign a clip, and play — all in one command:

[SerializeReference]
[JungleClassSelection]
private IProcess setupAndPlay = new AudioSourceCommand(
    new SetVolume(),
    new SetClip(),
    new Play()
);

In the Inspector, each operation appears as a toggleable entry. Enable only what you need.

Wait for a sound to finish before continuing

Add a PlayAudioOperation to an AudioSourceCommand. The command stays alive until the clip finishes:

[SerializeReference]
[JungleClassSelection]
private IProcess playAndWait = new AudioSourceCommand(
    new PlayAudioOperation()
);

Fade volume over time

Use AudioFloatPipelineOperation inside an AudioSourceCommand to drive volume with a lerped target and optional modifiers:

[SerializeReference]
[JungleClassSelection]
private IProcess fadeOut = new AudioSourceCommand(
    new AudioFloatPipelineOperation()
);

Configure the AudioFloatProperty to Volume, set the target to a lerped value, and add a clamp modifier if needed.

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.