Skip to content

AudioManager

ClassAudioToolAudioTool.Editor
public static class AudioManager

Audio playback and loading for the Audio Tool.

PlayFileAsync(string, bool, CancellationToken)

Section titled “PlayFileAsync(string, bool, CancellationToken)”
public static Task<bool> PlayFileAsync(string path, bool loop = false, CancellationToken token = default)

Plays a materialized file using the project’s available audio backend.

Parameters

NameType
pathSystem.String
loopSystem.Boolean
tokenSystem.Threading.CancellationToken

Returns

System.Threading.Tasks.Task{System.Boolean}

PlaySamplesAsync(float[], int, int, long, long, bool, CancellationToken)

Section titled “PlaySamplesAsync(float[], int, int, long, long, bool, CancellationToken)”
public static Task<bool> PlaySamplesAsync(float[] samples, int channels, int frequency, long startFrame, long endFrameExclusive, bool loop, CancellationToken token = default)

Plays processed interleaved samples without requiring a Unity AudioClip.

Parameters

NameType
samplesSystem.Single[]
channelsSystem.Int32
frequencySystem.Int32
startFrameSystem.Int64
endFrameExclusiveSystem.Int64
loopSystem.Boolean
tokenSystem.Threading.CancellationToken

Returns

System.Threading.Tasks.Task{System.Boolean}

public static void SeekCurrent(long frame)

Seeks the current editor audio preview to the specified sample frame.

Parameters

NameTypeDescription
frameSystem.Int64The zero-based sample frame at which playback should continue.
public static Task<AudioClip> LoadAudioFromFile(string filePath, bool allowStreaming = true)

Loads an audio file from disk.

Parameters

NameTypeDescription
filePathSystem.StringPath to the audio file
allowStreamingSystem.BooleanIf true, uses streaming for better performance. Set to false to access raw sample data.

Returns

System.Threading.Tasks.Task{UnityEngine.AudioClip}: The loaded AudioClip, or null if loading failed

public static void PlayClip(AudioClip clip, int startSample = 0, bool loop = false)

Plays an AudioClip directly.

Parameters

NameTypeDescription
clipUnityEngine.AudioClipThe audio clip to play
startSampleSystem.Int32Inclusive per-channel sample-frame index at which playback begins.
loopSystem.BooleanWhether to loop playback
public static void PlayClipRange(AudioClip clip, int startSample, int endSample, bool loop = false)

Plays a specific range of an AudioClip. Note: Due to Unity’s API limitations, this plays from startSample but doesn’t auto-stop at endSample. Use GetCurrentSamplePosition() to check and stop manually if needed.

Parameters

NameTypeDescription
clipUnityEngine.AudioClipThe audio clip to play
startSampleSystem.Int32Inclusive per-channel sample-frame index at which playback begins.
endSampleSystem.Int32Exclusive per-channel sample-frame index tracked as the requested end.
loopSystem.BooleanWhether to loop playback
public static float GetCurrentPosition()

Gets the current playback position in seconds.

Returns

System.Single: Current position in seconds, or 0 if not playing

public static int GetCurrentSamplePosition()

Gets the current playback position in samples.

Returns

System.Int32: Current sample position, or 0 if not playing

public static bool HasReachedRangeEnd()

Checks if the playback has reached the end of the specified range.

Returns

System.Boolean: True if range playback has completed

public static bool IsPlaying()

Checks if audio is currently playing.

Returns

System.Boolean: True if audio is playing

public static void PauseAudio()

Pauses the currently playing audio.

public static void ResumeAudio()

Resumes paused audio.

public static void StopAudio()

Stops audio playback.

public static EditorAudioMetadata? CurrentMetadata { get; }

Returns

System.Nullable{ImpossibleRobert.Common.EditorAudioMetadata}

public static AudioClip CurrentClip { get; }

Gets the clip most recently started through this manager, or null before playback.

Returns

UnityEngine.AudioClip

public static bool IsRangePlaying { get; }

Gets whether the current preview is being tracked against a requested sample range.

Returns

System.Boolean

public static int RangeEndSample { get; }

Gets the exclusive per-channel sample-frame index used to detect the end of range playback.

Returns

System.Int32

public static int RangeStartSample { get; }

Gets the inclusive per-channel sample-frame index where range playback started.

Returns

System.Int32