docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class AudioPreview

    An audio envelope with a play/stop control and an optional length readout.

    Inheritance
    object
    CallbackEventHandler
    Focusable
    VisualElement
    BaseVisualElement
    AudioPreview
    Implements
    IEventHandler
    IResolvedStyle
    ITransform
    ITransitionAnimations
    IExperimentalFeatures
    IVisualElementScheduler
    IContextOverrideElement
    IAdditionalDataHolder
    Inherited Members
    BaseVisualElement.contextPrefix
    BaseVisualElement.densityOverride
    BaseVisualElement.themeOverride
    BaseVisualElement.langOverride
    BaseVisualElement.layoutDirectionOverride
    BaseVisualElement.preferredTooltipPlacementOverride
    BaseVisualElement.tooltipDelayMsOverride
    BaseVisualElement.GetLayoutDirectionUssClassName(Dir)
    VisualElement.disabledUssClassName
    VisualElement.SetActivePseudoState(bool)
    VisualElement.SetCheckedPseudoState(bool)
    VisualElement.Focus()
    VisualElement.SendEvent(EventBase)
    VisualElement.SetEnabledFromHierarchy(bool)
    VisualElement.SetEnabled(bool)
    VisualElement.MarkDirtyRepaint()
    VisualElement.IsMarkedForRepaint()
    VisualElement.ContainsPoint(Vector2)
    VisualElement.Overlaps(Rect)
    VisualElement.DoMeasure(float, VisualElement.MeasureMode, float, VisualElement.MeasureMode)
    VisualElement.ToString()
    VisualElement.GetClasses()
    VisualElement.ClearClassList()
    VisualElement.AddToClassList(string)
    VisualElement.RemoveFromClassList(string)
    VisualElement.ToggleInClassList(string)
    VisualElement.EnableInClassList(string, bool)
    VisualElement.ClassListContains(string)
    VisualElement.FindAncestorUserData()
    VisualElement.SetBinding(BindingId, Binding)
    VisualElement.GetBinding(BindingId)
    VisualElement.TryGetBinding(BindingId, out Binding)
    VisualElement.GetBindingInfos()
    VisualElement.GetBindingInfos(List<BindingInfo>)
    VisualElement.HasBinding(BindingId)
    VisualElement.ClearBinding(BindingId)
    VisualElement.ClearBindings()
    VisualElement.GetHierarchicalDataSourceContext()
    VisualElement.GetDataSourceContext(BindingId)
    VisualElement.TryGetDataSourceContext(BindingId, out DataSourceContext)
    VisualElement.TryGetLastBindingToUIResult(in BindingId, out BindingResult)
    VisualElement.TryGetLastBindingToSourceResult(in BindingId, out BindingResult)
    VisualElement.Add(VisualElement)
    VisualElement.Insert(int, VisualElement)
    VisualElement.Remove(VisualElement)
    VisualElement.RemoveAt(int)
    VisualElement.Clear()
    VisualElement.ElementAt(int)
    VisualElement.IndexOf(VisualElement)
    VisualElement.Children()
    VisualElement.Sort(Comparison<VisualElement>)
    VisualElement.BringToFront()
    VisualElement.SendToBack()
    VisualElement.PlaceBehind(VisualElement)
    VisualElement.PlaceInFront(VisualElement)
    VisualElement.RemoveFromHierarchy()
    VisualElement.GetFirstOfType<T>()
    VisualElement.GetFirstAncestorOfType<T>()
    VisualElement.Contains(VisualElement)
    VisualElement.FindCommonAncestor(VisualElement)
    VisualElement.viewDataKey
    VisualElement.userData
    VisualElement.canGrabFocus
    VisualElement.focusController
    VisualElement.disablePlayModeTint
    VisualElement.usageHints
    VisualElement.transform
    VisualElement.scaledPixelsPerPoint
    VisualElement.layout
    VisualElement.contentRect
    VisualElement.paddingRect
    VisualElement.worldBound
    VisualElement.localBound
    VisualElement.worldTransform
    VisualElement.hasActivePseudoState
    VisualElement.hasInactivePseudoState
    VisualElement.hasHoverPseudoState
    VisualElement.hasCheckedPseudoState
    VisualElement.hasEnabledPseudoState
    VisualElement.hasDisabledPseudoState
    VisualElement.hasFocusPseudoState
    VisualElement.hasRootPseudoState
    VisualElement.pickingMode
    VisualElement.name
    VisualElement.enabledInHierarchy
    VisualElement.enabledSelf
    VisualElement.languageDirection
    VisualElement.visible
    VisualElement.generateVisualContent
    VisualElement.dataSource
    VisualElement.dataSourcePath
    VisualElement.dataSourceType
    VisualElement.experimental
    VisualElement.hierarchy
    VisualElement.cacheAsBitmap
    VisualElement.parent
    VisualElement.panel
    VisualElement.contentContainer
    VisualElement.visualTreeAssetSource
    VisualElement.this[int]
    VisualElement.childCount
    VisualElement.schedule
    VisualElement.style
    VisualElement.resolvedStyle
    VisualElement.customStyle
    VisualElement.styleSheets
    VisualElement.tooltip
    Focusable.Blur()
    Focusable.focusable
    Focusable.tabIndex
    Focusable.delegatesFocus
    CallbackEventHandler.RegisterCallback<TEventType>(EventCallback<TEventType>, TrickleDown)
    CallbackEventHandler.RegisterCallbackOnce<TEventType>(EventCallback<TEventType>, TrickleDown)
    CallbackEventHandler.RegisterCallback<TEventType, TUserArgsType>(EventCallback<TEventType, TUserArgsType>, TUserArgsType, TrickleDown)
    CallbackEventHandler.RegisterCallbackOnce<TEventType, TUserArgsType>(EventCallback<TEventType, TUserArgsType>, TUserArgsType, TrickleDown)
    CallbackEventHandler.RegisterCallback<TEventType>(EventCallback<TEventType>, CallbackOptions)
    CallbackEventHandler.RegisterCallback<TEventType, TUserArgsType>(EventCallback<TEventType, TUserArgsType>, TUserArgsType, CallbackOptions)
    CallbackEventHandler.UnregisterCallback<TEventType>(EventCallback<TEventType>, TrickleDown)
    CallbackEventHandler.UnregisterCallback<TEventType>(EventCallback<TEventType>, CallbackOptions)
    CallbackEventHandler.UnregisterCallback<TEventType, TUserArgsType>(EventCallback<TEventType, TUserArgsType>, TrickleDown)
    CallbackEventHandler.UnregisterCallback<TEventType, TUserArgsType>(EventCallback<TEventType, TUserArgsType>, CallbackOptions)
    CallbackEventHandler.UnregisterAllRemovableCallbacks()
    CallbackEventHandler.HasTrickleDownHandlers()
    CallbackEventHandler.HasBubbleUpHandlers()
    CallbackEventHandler.ExecuteDefaultActionAtTarget(EventBase)
    CallbackEventHandler.HandleEventBubbleUp(EventBase)
    CallbackEventHandler.HandleEventTrickleDown(EventBase)
    CallbackEventHandler.ExecuteDefaultAction(EventBase)
    CallbackEventHandler.NotifyPropertyChanged(in BindingId)
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    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

    Implements

    IEventHandler
    IResolvedStyle
    ITransform
    ITransitionAnimations
    IExperimentalFeatures
    IVisualElementScheduler
    IContextOverrideElement
    IAdditionalDataHolder

    Extension Methods

    VisualElementExtensions.FindNavController(VisualElement)
    RegisterUpdateCallbackExtensions.RegisterUpdateCallback(VisualElement, EventCallback<UpdateEvent>)
    RegisterUpdateCallbackExtensions.UnregisterUpdateCallback(VisualElement, EventCallback<UpdateEvent>)
    VisualElementExtensions.EnableDynamicTransform(VisualElement, bool)
    VisualElementExtensions.EnablePicking(VisualElement, bool)
    VisualElementExtensions.GetChildren<T>(VisualElement, bool)
    VisualElementExtensions.GetContextProvider<T>(VisualElement)
    VisualElementExtensions.GetContextProvider<T>(VisualElement, string)
    VisualElementExtensions.GetContext<T>(VisualElement)
    VisualElementExtensions.GetContext<T>(VisualElement, string)
    VisualElementExtensions.GetExclusiveRootElement(VisualElement)
    VisualElementExtensions.GetLastAncestorOfType<T>(VisualElement)
    VisualElementExtensions.GetPreferredTooltipPlacement(VisualElement)
    VisualElementExtensions.GetSelfContext<T>(VisualElement)
    VisualElementExtensions.GetSelfContext<T>(VisualElement, string)
    VisualElementExtensions.GetTooltipContent(VisualElement)
    VisualElementExtensions.GetTooltipTemplate(VisualElement)
    VisualElementExtensions.HasAncestorOfType<T>(VisualElement, bool)
    VisualElementExtensions.HasAncestorsOfType<T>(VisualElement)
    VisualElementExtensions.IsContextProvider<T>(VisualElement)
    VisualElementExtensions.IsContextProvider<T>(VisualElement, string)
    VisualElementExtensions.IsInvisible(VisualElement)
    VisualElementExtensions.IsOnScreen(VisualElement)
    VisualElementExtensions.ProvideContext<T>(VisualElement, string, T)
    VisualElementExtensions.ProvideContext<T>(VisualElement, T)
    VisualElementExtensions.RegisterContextChangedCallback<T>(VisualElement, string, EventCallback<ContextChangedEvent<T>>)
    VisualElementExtensions.RegisterContextChangedCallback<T>(VisualElement, EventCallback<ContextChangedEvent<T>>)
    VisualElementExtensions.SetPreferredTooltipPlacement(VisualElement, OptionalEnum<PopoverPlacement>)
    VisualElementExtensions.SetTooltipContent(VisualElement, VisualElementExtensions.TooltipContentCallback)
    VisualElementExtensions.SetTooltipTemplate(VisualElement, VisualElement)
    VisualElementExtensions.UnregisterContextChangedCallback<T>(VisualElement, string, EventCallback<ContextChangedEvent<T>>)
    VisualElementExtensions.UnregisterContextChangedCallback<T>(VisualElement, EventCallback<ContextChangedEvent<T>>)
    In This Article
    Back to top
    Copyright © 2026 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)