Skip to content

AudioManager

ClassAudioToolAudioTool.Editor
public static class AudioManager

Audio playback and loading for the Audio Tool.

public static AudioClip CurrentClip { get; }

Gets the currently playing audio clip.

Returns

UnityEngine.AudioClip — No return description is available.

public static bool IsRangePlaying { get; }

Gets whether range playback is active.

Returns

System.Boolean — No return description is available.

public static int RangeEndSample { get; }

Gets the range end sample for range playback.

Returns

System.Int32 — No return description is available.

public static int RangeStartSample { get; }

Gets the range start sample for range playback.

Returns

System.Int32 — No return description is available.

public static Task<AudioClip> LoadAudioFromFile(string filePath, bool allowStreaming = true)

Loads an audio file from disk.

Parameters

Name Type Description
filePath System.String Path to the audio file
allowStreaming System.Boolean If 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

Name Type Description
clip UnityEngine.AudioClip The audio clip to play
startSample System.Int32 Starting sample position
loop System.Boolean Whether 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

Name Type Description
clip UnityEngine.AudioClip The audio clip to play
startSample System.Int32 Starting sample position
endSample System.Int32 Ending sample position (for tracking purposes)
loop System.Boolean Whether 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.