Class AudioPreview
An audio envelope with a play/stop control and an optional length readout.
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class AudioPreview : BaseVisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder
Remarks
AudioPreview auditions a single clip. It is purely presentational: the caller owns the peak data, the playback state, the playhead and every string. Nothing here decodes or plays audio, so the same component serves an asset row, an inspector and a picker tile.
The body has a precedence order. message replaces the envelope outright and beats everything; loading shows a Skeleton while the envelope is being computed; a null peaks with a fallbackIcon set draws that symbol instead; otherwise the envelope is drawn by AudioWaveform. A null peaks with no fallback still draws, as a flat baseline — a clip whose envelope was never computed is still playable, and an empty box would read as a broken component rather than an unanalysed one.
The message, loading and fallback states are all driven from props precisely so a consumer that cannot compute an envelope — too large, decode refused, still fetching — or has chosen not to, can say so in its own words or with its own symbol without this component knowing why.
Examples
A clip with a computed envelope and a playhead.
var preview = new AudioPreview
{
peaks = envelope,
progress = 0.4f,
durationLabel = "0:12",
};
preview.toggled += () => TogglePlayback(preview);
parentElement.Add(preview);
A clip too large to analyse, naming the medium instead of drawing a flat line.
<appui:AudioPreview message="Clip too large to preview" duration-label="4:03" />
Constructors
AudioPreview()
Default constructor.
Declaration
public AudioPreview()
Fields
bodyUssClassName
The styling class of the body, which holds whichever of the four states is showing.
Declaration
public const string bodyUssClassName = "appui-audio-preview__body"
Field Value
| Type | Description |
|---|---|
| string |
durationUssClassName
The styling class of the length readout.
Declaration
public const string durationUssClassName = "appui-audio-preview__duration"
Field Value
| Type | Description |
|---|---|
| string |
fallbackIconUssClassName
The styling class of the fallback symbol shown in place of the envelope.
Declaration
public const string fallbackIconUssClassName = "appui-audio-preview__fallback-icon"
Field Value
| Type | Description |
|---|---|
| string |
flatUssClassName
The styling class applied to the envelope while it is a flat, uncomputed baseline.
Declaration
public const string flatUssClassName = "appui-audio-preview__waveform--flat"
Field Value
| Type | Description |
|---|---|
| string |
messageUssClassName
The styling class of the message shown in place of the envelope.
Declaration
public const string messageUssClassName = "appui-audio-preview__message"
Field Value
| Type | Description |
|---|---|
| string |
playButtonUssClassName
The styling class of the play/stop control.
Declaration
public const string playButtonUssClassName = "appui-audio-preview__play-button"
Field Value
| Type | Description |
|---|---|
| string |
skeletonUssClassName
The styling class of the loading placeholder.
Declaration
public const string skeletonUssClassName = "appui-audio-preview__skeleton"
Field Value
| Type | Description |
|---|---|
| string |
stripUssClassName
The styling class applied in the Strip layout.
Declaration
public const string stripUssClassName = "appui-audio-preview--strip"
Field Value
| Type | Description |
|---|---|
| string |
ussClassName
The AudioPreview main styling class.
Declaration
public const string ussClassName = "appui-audio-preview"
Field Value
| Type | Description |
|---|---|
| string |
waveformUssClassName
The styling class of the envelope.
Declaration
public const string waveformUssClassName = "appui-audio-preview__waveform"
Field Value
| Type | Description |
|---|---|
| string |
Properties
durationLabel
A pre-formatted length, rendered beside the control. Empty hides the readout.
Declaration
[CreateProperty]
[UxmlAttribute]
public string durationLabel { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Remarks
Pre-formatted on purpose: the host already knows whether it wants 0:12,
12s or a sample count, and this component has no clip to measure.
fallbackIcon
The name of a symbol drawn in place of the envelope while peaks is null.
Declaration
[CreateProperty]
[UxmlAttribute]
public string fallbackIcon { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Remarks
For a consumer that has no peak data and would rather name the medium than draw a flat line that reads as a silent recording. Named, not styled, by the consumer: the size and colour stay here so every such placeholder matches.
loading
Whether to show a placeholder while the envelope is being computed.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool loading { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
message
Text shown in place of the envelope. Takes precedence over loading and over the envelope itself.
Declaration
[CreateProperty]
[UxmlAttribute]
public string message { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
peaks
Normalized peak amplitudes, or null when there are none to draw.
Declaration
[CreateProperty]
public List<float> peaks { get; set; }
Property Value
| Type | Description |
|---|---|
| List<float> |
Remarks
A null envelope is not an error state. With no fallbackIcon set it draws a flat baseline, because the clip is still playable.
playLabel
The accessible label of the control while the clip is stopped.
Declaration
[CreateProperty]
[UxmlAttribute]
public string playLabel { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
playing
Whether the clip is currently playing. Drives which symbol and label the control shows.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool playing { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
previewLayout
How the control, the envelope and the length are laid out.
Declaration
[CreateProperty]
[UxmlAttribute("layout")]
public AudioPreviewLayout previewLayout { get; set; }
Property Value
| Type | Description |
|---|---|
| AudioPreviewLayout |
Remarks
Strip has no room for a symbol, so a null peaks draws the flat baseline there even when fallbackIcon is set.
progress
Playhead position as a 0..1 fraction. Unset hides it.
Declaration
[CreateProperty]
[UxmlAttribute]
public Optional<float> progress { get; set; }
Property Value
| Type | Description |
|---|---|
| Optional<float> |
stopLabel
The accessible label of the control while the clip is playing.
Declaration
[CreateProperty]
[UxmlAttribute]
public string stopLabel { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Events
toggled
Raised when the play/stop control is activated. The caller owns playback, so this only reports the intent to toggle; set playing to reflect the new state.
Declaration
public event Action toggled
Event Type
| Type | Description |
|---|---|
| Action |