Class
AudioPlayer
Used to play audio assets.
AudioPlayer is used to play audio assets. It provides a single
Output pin which can be connected to other pins via Wires.
Properties 14#
AssetContentId | The asset to be loaded into the AudioPlayer.ReadSafe |
AssetIdstring | The asset to be loaded into the AudioPlayer.ReadSafeDeprecatedHiddenNotReplicated |
AudioContentContent | The audio content to be loaded into the AudioPlayer.ReadSafeHidden |
AutoLoadboolean | Controls whether Asset loads automatically once
assigned.ReadSafe |
AutoPlayboolean | Denotes whether this AudioPlayer starts playing as soon as it
spawns in for the first time.ReadSafe |
IsPlayingboolean | Denotes whether this AudioPlayer is currently playing or planning
to play.Write: RobloxEngineSecurityReadSafe |
IsReadyboolean | Denotes whether this AudioPlayer is loaded, buffered, and ready to
play.ReadSafeReadOnlyNotReplicated |
Loopingboolean | Controls whether this AudioPlayer loops.ReadSafe |
LoopRegionNumberRange | A range, in seconds, denoting a desired loop start and loop end within the
PlaybackRegion of this
AudioPlayer.ReadSafe |
PlaybackRegionNumberRange | Range in seconds denoting a desired start time (minimum) and stop time
(maximum) within the TimeLength.ReadSafe |
PlaybackSpeeddouble | Controls how quickly the asset will be played, which controls its pitch.ReadSafe |
TimeLengthdouble | Denotes the length of the loaded asset.ReadSafeReadOnlyNotReplicated |
TimePositiondouble | Tracks the current position of the playhead within the asset.ReadSafe |
Volumefloat | Controls how loudly the asset will be played.ReadSafe |
Asset: ContentId#
ReadSafe
The asset to be loaded into the AudioPlayer. If
AutoLoad is true, the asset loads
immediately once this property is assigned. When loading is complete,
IsReady becomes true.
AssetId: string#
HiddenNotReplicatedDeprecatedReadSafeDeprecated
Deprecated. This property is deprecated; use Asset instead.
The asset to be loaded into the AudioPlayer. If
AutoLoad is true, the asset loads
immediately once this property is assigned. When loading is complete,
IsReady becomes true.
AudioContent: Content#
HiddenReadSafe
The audio content to be loaded into the AudioPlayer. If
AutoLoad is true, the asset loads
immediately once this property is assigned. When loading is complete,
IsReady becomes true.
AutoLoad: boolean#
ReadSafe
Controls whether Asset loads automatically once
assigned. If false, the asset will load upon the first attempt to play.
AutoPlay: boolean#
ReadSafe
Denotes whether this AudioPlayer starts playing as soon as it
enters the DataModel for the first time. This only applies to
AudioPlayers that are created or deserialized locally,
and does not apply to AudioPlayers generated via
replication. This property is primarily used at edit time in Studio to
have an AudioPlayer begin when entering a play session.
IsPlaying: boolean#
Write: RobloxEngineSecurityReadSafe
Denotes whether this AudioPlayer is currently playing or planning
to play. This property is read-only, but replicates. To play and stop an
AudioPlayer at runtime, use the Play()
and Stop() methods.
IsReady: boolean#
ReadOnlyNotReplicatedReadSafe
Denotes whether this AudioPlayer is loaded, buffered, and ready to
play. Although uncommon, AudioPlayers may have their
assets unloaded at runtime if there is extreme memory pressure, in which
case IsReady will become false.
Looping: boolean#
ReadSafe
Controls whether this AudioPlayer loops when exceeding the end of
its TimeLength,
LoopRegion, or
PlaybackRegion.
LoopRegion: NumberRange#
ReadSafe
A range, in seconds, denoting a desired loop start and loop end within the
PlaybackRegion of this
AudioPlayer.
If the LoopRegion minimum is greater
than the PlaybackRegion minimum, the
loop starts from the LoopRegion minimum.
If the LoopRegion minimum is less than
the PlaybackRegion minimum, the loop
starts from the PlaybackRegion minimum.
If the LoopRegion maximum is greater
than the PlaybackRegion maximum, the
loop ends at the PlaybackRegion
maximum.
If the LoopRegion maximum is less than
the PlaybackRegion maximum, the loop
ends at exactly the LoopRegion maximum.
If the LoopRegion minimum equals the
LoopRegion maximum, the AudioPlayer
uses the PlaybackRegion property
instead.
PlaybackRegion: NumberRange#
ReadSafe
Range in seconds denoting a desired start time (minimum) and stop time
(maximum) within the TimeLength.
If the PlaybackRegion minimum is
greater than 0, the sound begins playing from the
PlaybackRegion minimum time.
If the PlaybackRegion minimum is
less than 0, the sound begins playing from 0.
If the PlaybackRegion maximum is
greater than the TimeLength, the sound
stops at TimeLength.
If the PlaybackRegion maximum is
less than the TimeLength, the sound
stops at exactly the PlaybackRegion
maximum.
If the PlaybackRegion minimum
equals the PlaybackRegion maximum,
the sound plays in its entirety.
PlaybackSpeed: double#
ReadSafe
Multiplier controlling how quickly the asset will be played, directly controlling its perceived pitch. Ranges from 0 to 20.
TimeLength: double#
ReadOnlyNotReplicatedReadSafe
Denotes the length of the loaded Asset in
seconds.
TimePosition: double#
ReadSafe
Tracks and controls the current position of the playhead within the
Asset, in seconds.
Volume: float#
ReadSafe
Volume level which is multiplied onto the output audio stream, controlling how loudly the asset will be played. Ranges from 0 to 10.
Methods 7#
| Cancel | Attempts to cancel a pre-planned future Play or Stop command. |
| GetConnectedWires | Returns an array of Wires that are connected to the specified
pin. |
| GetInputPins | Gets the list of pins that Wire can use in Wire.TargetName
to connect to this instance via its Wire.TargetInstance property. |
| GetOutputPins | Gets the list of pins that Wire can use in Wire.SourceName
to connect to this instance via its Wire.SourceInstance property. |
| GetWaveformAsync | Returns a sampling of the waveform data for the loaded
Asset.Yields |
| Play | Plays the AudioPlayer from wherever its
TimePosition is. |
| Stop | Stops the AudioPlayer wherever its
TimePosition is. |
Cancel(actionId: int64?): boolean#
Attempts to cancel a Play() or
Stop() command that was scheduled to occur at a
future time. When Play() or
Stop() is called with an atTime argument, the
action is scheduled against
GetMixerTime() and the call returns a
unique actionId. Passing that actionId to this method prevents the
scheduled action from taking effect.
Returns true if the pending action was found and successfully cancelled.
Returns false if the action has already occurred, was never scheduled,
or the supplied actionId does not correspond to a pending action.
| Name | Type | Default | Description |
|---|---|---|---|
actionId | int64? | The unique-ID of a pre-planned Play or Stop command. |
Returns
boolean— Whether the cancellation was successful. Returns false if the action has already occurred, or otherwise does not exist.
GetConnectedWires(pin: string): List<Wire>#
Returns an array of Wires that are connected to the specified
pin. AudioPlayer has one "Output" pin.
| Name | Type | Default | Description |
|---|---|---|---|
pin | string | An input or output pin on this instance |
Returns
List<Wire>— An array ofWires
GetInputPins(): Array#
Gets the list of pins that Wire can use in Wire.TargetName
to connect to this instance via its Wire.TargetInstance property.
For AudioPlayer, there are none.
Returns
Array— An array of strings representing valid pin names.
GetOutputPins(): Array#
Gets the list of pins that Wire can use in Wire.SourceName
to connect to this instance via its Wire.SourceInstance property.
For AudioPlayer, this is Output only.
Returns
Array— An array of strings representing valid pin names.
GetWaveformAsync(timeRange: NumberRange, samples: int): Array#
Yields
Returns a sampling of the waveform data for the loaded
Asset, allowing you to check the volume of an
asset over its full duration without playing it. Unlike
AudioAnalyzer, which measures volume levels of a live audio stream
in real time, this method analyzes the asset ahead of time, making it
suitable for waverform visualization or logic that needs audio content
before playback begins.
| Name | Type | Default | Description |
|---|---|---|---|
timeRange | NumberRange | The start and end time (in seconds) of the segment to read. | |
samples | int | The number of samples to return for the specified range. |
Returns
Array— A table ofsamplesnumbers ranging between -1 and 1 representing the sampled waveform, or an empty table if a waveform could not be read.
Play(atTime: double?): int64?#
Plays the AudioPlayer from wherever its
TimePosition is. Replicates from server
to client. When atTime is provided, the action is scheduled against
GetMixerTime() for sample-accurate,
framerate-independent timing — useful for rhythm games or any scenario
where audio changes must align precisely with a beat.
| Name | Type | Default | Description |
|---|---|---|---|
atTime | double? | A specific time, based on
GetMixerTime, that this
AudioPlayer should begin playing at. |
Returns
int64?— IfatTimewas provided, a unique ID, which can be passed toCancel().
Stop(atTime: double?): int64?#
Stops the AudioPlayer wherever its
TimePosition is. Replicates from server
to client. When atTime is provided, the action is scheduled against
GetMixerTime() for sample-accurate,
framerate-independent timing, enabling precise beat-synchronized stops or
track transitions.
| Name | Type | Default | Description |
|---|---|---|---|
atTime | double? | A specific time, based on
GetMixerTime, that this
AudioPlayer should stop playing at. |
Returns
int64?— IfatTimewas provided, a unique ID, which can be passed toCancel().
Events 3#
| Ended | Fires when the AudioPlayer has completed playback and stopped. |
| Looped | Fires when the AudioPlayer loops. |
| WiringChanged | Fires when another instance is connected to or disconnected from the
AudioPlayer via a Wire. |
Ended()#
Fires after the AudioPlayer has completed playback and stopped.
Note this event will not fire for audio with
Looping set to true since it continues
playing upon reaching its end. This event will also not fire when the
audio is stopped before playback has completed; for this, use
AudioPlayer:GetPropertyChangedSignal() on the
IsPlaying property.
This event is often used to destroy an AudioPlayer when it has
completed playback.
Looped()#
Event that fires after the AudioPlayer loops. This happens when
the audio reaches the end of its content (or the end of the
LoopRegion if it is active) and
Looping is true.
This event does not fire if the audio is looped manually by changing
its TimePosition.
WiringChanged(connected: boolean, pin: string, wire: Wire, instance: Instance)#
Event that fires after a Wire becomes connected or disconnected,
and that Wire is now or was previously connected to a pin on the
AudioPlayer and to some other wirable instance.
| Name | Type | Default | Description |
|---|---|---|---|
connected | boolean | Whether the instance got connected or disconnected. | |
pin | string | The pin on the AudioPlayer that the Wire targets. | |
wire | Wire | The Wire between the AudioPlayer and the other
instance. | |
instance | Instance | The other instance that is or was connected through the Wire. |
Inherited members#
Inherited from Instance 58
Properties (10)
Archivable, archivable, Capabilities, IsInSandbox, Name, Parent, PredictionMode, RobloxLocked, Sandboxed, UniqueId
Methods (39)
AddTag, children, ClearAllChildren, Clone, clone, Destroy, destroy, FindFirstAncestor, FindFirstAncestorOfClass, FindFirstAncestorWhichIsA, FindFirstChild, findFirstChild, FindFirstChildOfClass, FindFirstChildWhichIsA, FindFirstDescendant, GetActor, GetAttribute, GetAttributeChangedSignal, GetAttributes, GetChildren, getChildren, GetDebugId, GetDescendants, GetFullName, GetStyled, GetStyledPropertyChangedSignal, GetTags, HasTag, IsAncestorOf, IsDescendantOf, isDescendantOf, IsPropertyModified, QueryDescendants, Remove, remove, RemoveTag, ResetPropertyToDefault, SetAttribute, WaitForChild