代码拉取完成,页面将自动刷新
# AudioSource
**Description:**
  A record that represents an audio source.
**Class Object:** [AudioSource Class](/docs/api/Class%20Object/AudioSource).
**Inherits from:** [Node](/docs/api/Class/Node).
## AudioSource.AttenuationModel
**Type:** Enumeration.
**Description:**
  The model of the attenuation.
**Signature:**
```tl
enum AttenuationModel
"NoAttenuation"
"InverseDistance"
"LinearDistance"
"ExponentialDistance"
end
```
## volume
**Type:** Field.
**Description:**
  The volume of the audio source. The value is between 0.0 and 1.0.
**Signature:**
```tl
volume: number
```
## pan
**Type:** Field.
**Description:**
  The pan of the audio source. The value is between -1.0 and 1.0.
**Signature:**
```tl
pan: number
```
## looping
**Type:** Field.
**Description:**
  Whether the audio source is looped.
**Signature:**
```tl
looping: boolean
```
## playing
**Type:** Field.
**Description:**
  Whether the audio source is playing.
**Signature:**
```tl
playing: boolean
```
## seek
**Type:** Function.
**Description:**
  Seeks to the specified time in the audio source.
**Signature:**
```tl
seek: function(self: AudioSource, startTime: number)
```
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| startTime | number | The time to seek to. |
## scheduleStop
**Type:** Function.
**Description:**
  Schedules the stop of the audio source.
**Signature:**
```tl
scheduleStop: function(self: AudioSource, timeToStop: number)
```
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| timeToStop | number | The time to stop the audio source. |
## stop
**Type:** Function.
**Description:**
  Stops the audio source.
**Signature:**
```tl
stop: function(self: AudioSource, fadeTime?: number)
```
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| fadeTime | number | The time to fade the audio source. Default is 0 seconds. |
## play
**Type:** Function.
**Description:**
  Plays the audio source.
**Signature:**
```tl
play: function(self: AudioSource, delayTime?: number): boolean
```
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| delayTime | number | [optional] The time to delay before playing the audio source. Default is 0 seconds. |
**Returns:**
| Return Type | Description |
| --- | --- |
| boolean | Whether the audio source was played successfully. |
## playBackground
**Type:** Function.
**Description:**
  Plays the audio source as a background audio.
**Signature:**
```tl
playBackground: function(self: AudioSource): boolean
```
**Returns:**
| Return Type | Description |
| --- | --- |
| boolean | Whether the audio source was played successfully. |
## play3D
**Type:** Function.
**Description:**
  Plays the audio source as a 3D audio.
**Signature:**
```tl
play3D: function(self: AudioSource, delayTime?: number): boolean
```
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| delayTime | number | [optional] The time to delay before playing the audio source. Default is 0 seconds. |
**Returns:**
| Return Type | Description |
| --- | --- |
| boolean | Whether the audio source was played successfully. |
## setProtected
**Type:** Function.
**Description:**
  Sets the protected state of the audio source. If the audio source is protected, it won't get stopped if we run out of voices.
**Signature:**
```tl
setProtected: function(self: AudioSource, var: boolean)
```
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| var | boolean | The protected state to set. |
## setLoopPoint
**Type:** Function.
**Description:**
  Sets the loop point of the audio source. The audio source will loop from the specified time to the end of the audio.
**Signature:**
```tl
setLoopPoint: function(self: AudioSource, loopStartTime: number)
```
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| loopStartTime | number | The time to loop the audio source. |
## setVelocity
**Type:** Function.
**Description:**
  Sets the velocity of the 3D audio source.
**Signature:**
```tl
setVelocity: function(self: AudioSource, vx: number, vy: number, vz: number)
```
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| vx | number | The x-axis velocity. |
| vy | number | The y-axis velocity. |
| vz | number | The z-axis velocity. |
## setMinMaxDistance
**Type:** Function.
**Description:**
  Sets the minimum and maximum distance of the 3D audio source.
**Signature:**
```tl
setMinMaxDistance: function(self: AudioSource, min: number, max: number)
```
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| min | number | The minimum distance. |
| max | number | The maximum distance. |
## setAttenuation
**Type:** Function.
**Description:**
  Sets the attenuation model of the 3D audio source.
**Signature:**
```tl
setAttenuation: function(self: AudioSource, model: AttenuationModel, factor: number)
```
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| model | AttenuationModel | The model of the attenuation. |
| factor | number | The factor of the attenuation. |
## setDopplerFactor
**Type:** Function.
**Description:**
  Sets the Doppler factor of the 3D audio source.
**Signature:**
```tl
setDopplerFactor: function(self: AudioSource, factor: number)
```
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| factor | number | The factor of the Doppler effect. |
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。