Class · inherits Instance
AudioPlayer
Used to play audio assets.
About AudioPlayer
AudioPlayer is used to play audio assets. It provides a single
Output pin which can be connected to other pins via Wires.
Properties 13
Asset
: ContentIdThe asset to be loaded into theAudioPlayer.The asset to be loaded into the
AudioPlayer. IfAutoLoadistrue, the asset loads immediately once this property is assigned. When loading is complete,IsReadybecomestrue.AudioContent
: ContentHiddenThe audio content to be loaded into theAudioPlayer.The audio content to be loaded into the
AudioPlayer. IfAutoLoadistrue, the asset loads immediately once this property is assigned. When loading is complete,IsReadybecomestrue.AutoPlay
: booleanDenotes whether thisAudioPlayerstarts playing as soon as it spawns in for the first time.Denotes whether this
AudioPlayerstarts playing as soon as it enters theDataModelfor the first time. This only applies toAudioPlayersthat are created or deserialized locally, and does not apply toAudioPlayersgenerated via replication. This property is primarily used at edit time in Studio to have anAudioPlayerbegin when entering a play session.IsPlaying
: booleanDenotes whether thisAudioPlayeris currently playing or planning to play.Denotes whether this
AudioPlayeris currently playing or planning to play. This property is read-only, but replicates. To play and stop anAudioPlayerat runtime, use thePlay()andStop()methods.IsReady
: booleanReadOnlyNotReplicatedDenotes whether thisAudioPlayeris loaded, buffered, and ready to play.Denotes whether this
AudioPlayeris loaded, buffered, and ready to play. Although uncommon,AudioPlayersmay have their assets unloaded at runtime if there is extreme memory pressure, in which caseIsReadywill become false.Looping
: booleanControls whether thisAudioPlayerloops.Controls whether this
AudioPlayerloops when exceeding the end of itsTimeLength,LoopRegion, orPlaybackRegion.LoopRegion
: NumberRangeA range, in seconds, denoting a desired loop start and loop end within thePlaybackRegionof thisAudioPlayer.A range, in seconds, denoting a desired loop start and loop end within the
PlaybackRegionof thisAudioPlayer.If the
LoopRegionminimum is greater than thePlaybackRegionminimum, the loop starts from theLoopRegionminimum.If the
LoopRegionminimum is less than thePlaybackRegionminimum, the loop starts from thePlaybackRegionminimum.If the
LoopRegionmaximum is greater than thePlaybackRegionmaximum, the loop ends at thePlaybackRegionmaximum.If the
LoopRegionmaximum is less than thePlaybackRegionmaximum, the loop ends at exactly theLoopRegionmaximum.If the
LoopRegionminimum equals theLoopRegionmaximum, theAudioPlayeruses thePlaybackRegionproperty instead.PlaybackRegion
: NumberRangeRange in seconds denoting a desired start time (minimum) and stop time (maximum) within theTimeLength.Range in seconds denoting a desired start time (minimum) and stop time (maximum) within the
TimeLength.If the
PlaybackRegionminimum is greater than 0, the sound begins playing from thePlaybackRegionminimum time.If the
PlaybackRegionminimum is less than 0, the sound begins playing from 0.If the
PlaybackRegionmaximum is greater than theTimeLength, the sound stops atTimeLength.If the
PlaybackRegionmaximum is less than theTimeLength, the sound stops at exactly thePlaybackRegionmaximum.If the
PlaybackRegionminimum equals thePlaybackRegionmaximum, the sound plays in its entirety.PlaybackSpeed
: doubleControls how quickly the asset will be played, which controls its pitch.Multiplier controlling how quickly the asset will be played, directly controlling its perceived pitch. Ranges from 0 to 20.
TimeLength
: doubleReadOnlyNotReplicatedDenotes the length of the loaded asset.Denotes the length of the loaded
Assetin seconds.TimePosition
: doubleTracks the current position of the playhead within the asset.Tracks and controls the current position of the playhead within the
Asset, in seconds.Volume
: floatControls how loudly the asset will be played.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
(actionId: int64?) → booleanAttempts to cancel a pre-planned futurePlayorStopcommand.Attempts to cancel a
Play()orStop()command that was scheduled to occur at a future time. WhenPlay()orStop()is called with anatTimeargument, the action is scheduled againstGetMixerTime()and the call returns a uniqueactionId. Passing thatactionIdto this method prevents the scheduled action from taking effect.Returns
trueif the pending action was found and successfully cancelled. Returnsfalseif the action has already occurred, was never scheduled, or the suppliedactionIddoes not correspond to a pending action.GetConnectedWires
(pin: string) → List<Wire>Returns an array ofWiresthat are connected to the specified pin.Returns an array of
Wiresthat are connected to the specified pin.AudioPlayerhas one "Output" pin.GetInputPins
() → ArrayGets the list of pins thatWirecan use inWire.TargetNameto connect to this instance via itsWire.TargetInstanceproperty.Gets the list of pins that
Wirecan use inWire.TargetNameto connect to this instance via itsWire.TargetInstanceproperty.For
AudioPlayer, there are none.GetOutputPins
() → ArrayGets the list of pins thatWirecan use inWire.SourceNameto connect to this instance via itsWire.SourceInstanceproperty.Gets the list of pins that
Wirecan use inWire.SourceNameto connect to this instance via itsWire.SourceInstanceproperty.For
AudioPlayer, this isOutputonly.GetWaveformAsync
(timeRange: NumberRange, samples: int) → ArrayYieldsReturns a sampling of the waveform data for the loadedAsset.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. UnlikeAudioAnalyzer, 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.Play
(atTime: double?) → int64?Plays theAudioPlayerfrom wherever itsTimePositionis.Plays the
AudioPlayerfrom wherever itsTimePositionis. Replicates from server to client. WhenatTimeis provided, the action is scheduled againstGetMixerTime()for sample-accurate, framerate-independent timing — useful for rhythm games or any scenario where audio changes must align precisely with a beat.Stop
(atTime: double?) → int64?Stops theAudioPlayerwherever itsTimePositionis.Stops the
AudioPlayerwherever itsTimePositionis. Replicates from server to client. WhenatTimeis provided, the action is scheduled againstGetMixerTime()for sample-accurate, framerate-independent timing, enabling precise beat-synchronized stops or track transitions.
Events 3
Ended
AudioPlayer.Ended:Connect(function())Fires when theAudioPlayerhas completed playback and stopped.Fires after the
AudioPlayerhas completed playback and stopped. Note this event will not fire for audio withLoopingset totruesince it continues playing upon reaching its end. This event will also not fire when the audio is stopped before playback has completed; for this, useAudioPlayer.GetPropertyChangedSignalon theIsPlayingproperty.This event is often used to destroy an
AudioPlayerwhen it has completed playback.Looped
AudioPlayer.Looped:Connect(function())Fires when theAudioPlayerloops.Event that fires after the
AudioPlayerloops. This happens when the audio reaches the end of its content (or the end of theLoopRegionif it is active) andLoopingistrue.This event does not fire if the audio is looped manually by changing its
TimePosition.WiringChanged
AudioPlayer.WiringChanged:Connect(function(connected, pin, wire, instance))Fires when another instance is connected to or disconnected from theAudioPlayervia aWire.Event that fires after a
Wirebecomes connected or disconnected, and thatWireis now or was previously connected to a pin on theAudioPlayerand to some other wirable instance.
AudioPlayer also has every member of Instance. Deprecated and Roblox-only members are hidden.
Reference text from the Roblox Creator Documentation, licensed CC BY 4.0, reorganized by rbxtoolshub.com · Studio 0.743.0.7431133.