Roblox UtilitiesDevlHub Roblox Documentation

Class

AudioPlayer

Inherits
Instance › Object
Memory category
Internal

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#

AssetContentIdThe asset to be loaded into the AudioPlayer.ReadSafe
AssetIdstringThe asset to be loaded into the AudioPlayer.ReadSafeDeprecatedHiddenNotReplicated
AudioContentContentThe audio content to be loaded into the AudioPlayer.ReadSafeHidden
AutoLoadbooleanControls whether Asset loads automatically once assigned.ReadSafe
AutoPlaybooleanDenotes whether this AudioPlayer starts playing as soon as it spawns in for the first time.ReadSafe
IsPlayingbooleanDenotes whether this AudioPlayer is currently playing or planning to play.Write: RobloxEngineSecurityReadSafe
IsReadybooleanDenotes whether this AudioPlayer is loaded, buffered, and ready to play.ReadSafeReadOnlyNotReplicated
LoopingbooleanControls whether this AudioPlayer loops.ReadSafe
LoopRegionNumberRangeA range, in seconds, denoting a desired loop start and loop end within the PlaybackRegion of this AudioPlayer.ReadSafe
PlaybackRegionNumberRangeRange in seconds denoting a desired start time (minimum) and stop time (maximum) within the TimeLength.ReadSafe
PlaybackSpeeddoubleControls how quickly the asset will be played, which controls its pitch.ReadSafe
TimeLengthdoubleDenotes the length of the loaded asset.ReadSafeReadOnlyNotReplicated
TimePositiondoubleTracks the current position of the playhead within the asset.ReadSafe
VolumefloatControls 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#

CancelAttempts to cancel a pre-planned future Play or Stop command.
GetConnectedWiresReturns an array of Wires that are connected to the specified pin.
GetInputPinsGets the list of pins that Wire can use in Wire.TargetName to connect to this instance via its Wire.TargetInstance property.
GetOutputPinsGets the list of pins that Wire can use in Wire.SourceName to connect to this instance via its Wire.SourceInstance property.
GetWaveformAsyncReturns a sampling of the waveform data for the loaded Asset.Yields
PlayPlays the AudioPlayer from wherever its TimePosition is.
StopStops 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.

NameTypeDefaultDescription
actionIdint64?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.

NameTypeDefaultDescription
pinstringAn input or output pin on this instance
Returns
  • List<Wire> — An array of Wires

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.

NameTypeDefaultDescription
timeRangeNumberRangeThe start and end time (in seconds) of the segment to read.
samplesintThe number of samples to return for the specified range.
Returns
  • Array — A table of samples numbers 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.

NameTypeDefaultDescription
atTimedouble?A specific time, based on GetMixerTime, that this AudioPlayer should begin playing at.
Returns
  • int64? — If atTime was provided, a unique ID, which can be passed to Cancel().

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.

NameTypeDefaultDescription
atTimedouble?A specific time, based on GetMixerTime, that this AudioPlayer should stop playing at.
Returns
  • int64? — If atTime was provided, a unique ID, which can be passed to Cancel().

Events 3#

EndedFires when the AudioPlayer has completed playback and stopped.
LoopedFires when the AudioPlayer loops.
WiringChangedFires 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.

NameTypeDefaultDescription
connectedbooleanWhether the instance got connected or disconnected.
pinstringThe pin on the AudioPlayer that the Wire targets.
wireWireThe Wire between the AudioPlayer and the other instance.
instanceInstanceThe other instance that is or was connected through the Wire.

Inherited members#

Inherited from Instance 58
Inherited from Object 6
Properties (2)

ClassName, className

Events (1)

Changed